Welcome Guest, Not a member yet? Register   Sign In
internal redirect
#1

[eluser]Unknown[/eluser]
Hello,


Is it possible to do internal redirects in codeIgniter ?

by internal redirects I mean: from one controller, being able to call another controller and let the new controller finish the request.

thank you
#2

[eluser]Matthew Pennell[/eluser]
[quote author="emilper" date="1191333206"]Is it possible to do internal redirects in codeIgniter ?

by internal redirects I mean: from one controller, being able to call another controller and let the new controller finish the request.[/quote]
It depends how much the new controller needs to know about what has gone on in the original controller. You can do a simple redirect:
Code:
redirect('newcontroller/method', 'location');
#3

[eluser]freaksauce[/eluser]
I'm not sure how correct this is but I used the method above of redirecting and then using the Native Session class (or the new Session class coming soon) you can use Flashdata variables for anything that is needed in the next request.
#4

[eluser]Unknown[/eluser]
redirect() tells the browser to connect to the new url.

What I was inquiring for was a method to call a controller from another controller. I have found that I can call, from withing the same controller, another method, which is an "internal redirect".

It would be nice if there were a way to give up execution to another controller, i.e. another method in another controller class.

Code Igniter is cool, anyway, and even if such thing is not possible, I'll stick with it for the current project Smile

thanks to all that answered

E.
#5

[eluser]CI Lee[/eluser]
What about using the urls to pass data to the next controller...
Code:
redirect('newfunction/blah/'$data);

And then grabbing it using
Code:
$this->uri->segment(3)


Might help....
#6

[eluser]esra[/eluser]
[quote author="emilper" date="1191415801"]redirect() tells the browser to connect to the new url.

What I was inquiring for was a method to call a controller from another controller. I have found that I can call, from withing the same controller, another method, which is an "internal redirect".

It would be nice if there were a way to give up execution to another controller, i.e. another method in another controller class.

Code Igniter is cool, anyway, and even if such thing is not possible, I'll stick with it for the current project Smile

thanks to all that answered

E.[/quote]

I have not tried the feature myself, but the latest version of the Modular Separation extensions by Zacharias does allow controllers to call methods in other controllers. However, I do use modular separation. This was handled by adding new methods to the Loader and Router libraries via extensions. If you're interested, there is a wiki articles as well as a long thread. The functionality has nothing to do with redirects.

If modular separation is not to your liking, you can create a base controller class and extend all of your controller classes from that base controller. In the base controller, you could place any methods you want to share among your controllers or load a library in base controller's constructor with the methods you want to share.




Theme © iAndrew 2016 - Forum software by © MyBB