Welcome Guest, Not a member yet? Register   Sign In
Best practice: call controller from controller?
#1

[eluser]flokky[/eluser]
Hi,

I'm working on a website which exists out of different kind of business logic. In order to use the correct OO principle I've splitted my logic into different kinds of controllers, views.

Now I want to combine those controllers into one view. I guess I have to call a controller from the 'combined' controller. Is that correct and would you do this?

Example to understand what I'm saying:
Controller A - get some name out of db
Controller B - show list of the logged in user

Controller C - combined call to controller A and B to show this into one view.

Thanks
#2

[eluser]schnoodles[/eluser]
ok for what you just said Controller A and Controller B should really be models.

for example

Code:
class MyController extends Controller {

  function MyController { parent::Controller(); }

  function index() {

    $data['names'] = $this->UserModel->getSomeNames();
    $data['users'] = $this->UserModel->getLoggedUsers();

    $this->load->view('view',$data);

  }

}
#3

[eluser]flokky[/eluser]
It looks so simple if you put it that way. I thought I had to create a controller for every model I made.

Thank you for the quick and accurate response.
#4

[eluser]wiredesignz[/eluser]
Think of Controllers as managing your logic related to the page URI. (Apply security etc...)
Models are information stores to provide data to the Controller and/or the View.

The Model can store any kind of data you need to access, not just database stuff.


Hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB