Welcome Guest, Not a member yet? Register   Sign In
view with multiple information origin
#1

[eluser]Ajaxian64[/eluser]
Hello,

I would like to do something very basic.
Suppose I have 2 controllers, and 2 associated models
I have a view, in which controller 1 send its data (coming from model1), but in a part of the view I have to load also some data which are coming from model 2

typically this situation takes place on blog system where when you edit a post you have mapped on the same view, the list of categories.
I think that view combines data from Post model and data from category model.

Question is: how can handle this with CI ?
the view is displayed by controller1 but inside view data shall be retreived from model2

In cakePhp it is the solved by the use of
$sidebar = $this->requestAction(array('plugin'=>null,'controller'=>'Tags','action'=>'getList')) ;

Thanks
#2

[eluser]mddd[/eluser]
A model is not confined to a single controller. For instance, a category model will probably be used in many controllers. If you have a Home controller, a Post controller, an Archive controller, they will all need the Category model.

So: just load all the models you need into your controller. Put the data together and output it to the view. Like so (this is a simplification of course):
Code:
$this->load->model('post_model');
$this->load->model('category_model');

$postinfo = $this->post_model->get_post($postid);
$cats = $this->category_model->get_list();

$this->load->view('post', array(compact('postinfo', 'cats')));
#3

[eluser]Ajaxian64[/eluser]
Thank you mddd
just simple and efficient.




Theme © iAndrew 2016 - Forum software by © MyBB