Welcome Guest, Not a member yet? Register   Sign In
model/view/controller logic
#1

[eluser]marc0[/eluser]
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:
--
Code:
$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 :
Code:
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 ?!



#2

[eluser]marc0[/eluser]
Found this !
http://stackoverflow.com/questions/34944...iter-query
#3

[eluser]marc0[/eluser]
Here's what I was looking for, all done inside the controller.

Code:
$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();
}
#4

[eluser]jmadsen[/eluser]
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/n...rscore-php

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




Theme © iAndrew 2016 - Forum software by © MyBB