CodeIgniter - call another controller from a controller

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

Moderator: General Moderators

Post Reply
tigor
Forum Newbie
Posts: 2
Joined: Mon Aug 29, 2011 11:06 am

CodeIgniter - call another controller from a controller

Post by tigor »

I know this is not the best practice, but feels like i really need to reference another controller from some other controller.
Here is the deal -
1. I have service controller, which wraps some functionality of a web application.
2. The web application controller on every request verifies session.
3. In order to create a session in a service, I extend the Login controller, do the login and then i need to call for a controller of a web application.
I could simply duplicate the code, but this seems even worse then accessing controller.

If i simply instance the class, naturally the class has no controller context, thus, somehow i need to get reference to that controller from the CodeIgniter.
Any suggestions ?

Thank you in advance.
greip
Forum Commoner
Posts: 39
Joined: Tue Aug 23, 2011 8:23 am
Location: Oslo, Norway

Re: CodeIgniter - call another controller from a controller

Post by greip »

When the login controller finish doing its stuff, do a 302 redirect to the page you want the user to see next.
uday8486
Forum Newbie
Posts: 22
Joined: Fri Oct 28, 2011 11:42 pm
Location: Pune, India

Re: CodeIgniter - call another controller from a controller

Post by uday8486 »

You actually can't call a controller within a controller, You can use helper to accomplish your task.

Or Can view this link to get a better idea
http://codeigniter.com/forums/viewthread/55212/
Post Reply