Reputation: 1049
does it exist a way to pass data from a controller to on other controller using php framework CodeIgniter?I mean I have some data in a controller and I would pass them to another controller....
Upvotes: 1
Views: 322
Reputation: 9547
Your question kind of defeats the purpose of the MVC pattern. Controllers shouldn't have to "know about each other." You might have serious coupling issues if that's the case.
If you can, try to "pass" information through the URI (which is statelessly RESTful) like @stormdrain suggests. If you can't maintain statelessness, go with session data.
Session data is a little more suited for what you're doing, particularly if you need the application to "remember" something that happened earlier in the session. CI has a pretty good internal library for this (though it's not without some documented flaws, fair warning):
http://codeigniter.com/user_guide/libraries/sessions.html
Upvotes: 1
Reputation: 7895
$_POST
data will pass data along to another controller. You can also user params like so:
class Test extends CI_Controller{
function page($param=""){
echo $param;
}
}
http://site.local/test/page/blah will give you a blank page with the word "blah". However, it's not a good idea to pass data via params outside of int's (like id's)... often you will have disallowed url characters if not using int's.
Upvotes: 0