Code-Igniter: calling a controller within a controller

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Code-Igniter: calling a controller within a controller

Postby Live24x7 » Sat Aug 04, 2012 2:17 pm

Hello - this pertains to CI but i guess the issue is similar for all frameworks.

I am using an authentication library (tank-auth) to handle login/registration etc.
- so i already have an auth controller ( say Controller A) - with a method 'login' - that calls the view 'login-form'.

This is working perfectly well. So far so good

However now i need to show the login form on the top of each page (say on home page) - this home page is controlled by a different controller - say Controller B.

Now how do i call the method in controller B (say the login method) from controller A ?
Live24x7
Forum Contributor
 
Posts: 194
Joined: Sat Nov 19, 2011 10:32 am

Re: Code-Igniter: calling a controller within a controller

Postby Live24x7 » Sat Aug 04, 2012 2:32 pm

some quick search seems to be pointing out in the direction of modular development (HMVC) - but i am not sure how to apply this to CI.

Isnt' MVC supposed to ease out development ? so wht is the fuss of it not being modular and why cant it handle two or more modules display per page ?
Live24x7
Forum Contributor
 
Posts: 194
Joined: Sat Nov 19, 2011 10:32 am

Re: Code-Igniter: calling a controller within a controller

Postby greyhoundcode » Tue Aug 14, 2012 8:06 am

Yeah this is something that, for instance, Kohana and Fuel are both set up for. It's been a while since I used CI and this approach may no longer work/may be greeted by cries of anguish because it's some kind of bad practice, but I seem to remember trying to do something similar ages ago with CI. I simply used a wrapper function that instantiated the controller class and called the relevant action, I can't remember if it used output buffering or not, I don't think it was necessary though.
User avatar
greyhoundcode
Forum Regular
 
Posts: 611
Joined: Mon Feb 11, 2008 5:22 am

Re: Code-Igniter: calling a controller within a controller

Postby Live24x7 » Tue Aug 14, 2012 10:58 am

I eventually did something similar using wrapper of sorts.
and this is one reason why I later moved to YII framework - (widgets and modules are inherently supported) - though i am still trying to figure out YII in its entirety.
Live24x7
Forum Contributor
 
Posts: 194
Joined: Sat Nov 19, 2011 10:32 am


Return to PHP - Frameworks

Who is online

Users browsing this forum: No registered users and 1 guest