• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
model/view/controller logic

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);
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 ?!

Found this !

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

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

foreach($properties as &$p){
  $this->db->where('open_house.mls', $p->mls);
  $p->open_houses = $this->db->get()->result();

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:


(Today seems to be "Plug my Blog Day" :-) )

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.