EllisLab text mark
Advanced Search
     
model/view/controller logic
Posted: 05 October 2012 12:51 PM   [ Ignore ]
Joined: 2012-10-05
3 posts

Hey, just getting into codeIgniter, what a great platform !

Here’s the situation :

I have a controller that gets real-estate listings (properties) from a listings table
Now I have another table, containing open houses infos.

So in my properties controller:

$data['proprietes'$this->model_proprietes->get_proprietes($config['per_page']$offset);
...
$this->template->write_view('content''properties'$data);
$this->template->render(); 


Now i need to add openhouse infos to the listings.

The only way I can think of getting every open houses would be like this inside my properties view :

foreach ($properties as $p{
echo 'MLS: ' $p->mls;
echo 
'Open houses? ';
$open_houses $this->model_proprietes->get_open_houses($p->mls);
foreach (
$open_houses as $open_house)
echo $open_house->details}


Thit just looks like horrible MVC programming to me… any suggestions ?!

 

 

 
Posted: 05 October 2012 01:15 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-10-05
3 posts

Found this !
http://stackoverflow.com/questions/3494463/retrieve-second-table-as-subarray-in-codeigniter-query

 
Posted: 06 October 2012 11:42 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-10-05
3 posts

Here’s what I was looking for, all done inside the controller.

$properties $this->db->get('properties')->result();

foreach(
$properties as &$p){
  $this
->db->from('open_houses');
  
$this->db->where('open_house.mls'$p->mls);
  
$p->open_houses $this->db->get()->result();
 
Posted: 06 October 2012 06:45 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2009-04-15
453 posts

Use a database join.

If you have formatting issues, try working with underscore.php or similar. Here’s a quick tut I wrote to show how easy it is & how much performance you can save:

http://www.codebyjeff.com/blog/2012/08/no-more-machine-gunning-use-underscore-php

(Today seems to be “Plug my Blog Day” grin  )

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?