Welcome Guest, Not a member yet? Register   Sign In
post data between controllers
#2

Personally, I think it is very bad practice to have one controller call another (unless you are using wiredesignz HMVC, which I have always found to be overkill in truth).

The idea is that a request is passed to a controller. The controller deals with the request by calling models for data, or libraries for business logic, or whatever. It then calls the views for the response.

The only real exception I can think of is if you do a redirect. With a redirect the controller is really saying that this request needs to be dealt with by another controller. If your controller method has arguments, data can be passed via those arguments. An alternative but IMHO messier way is to load the data into a session variable (perhaps as a flash-data) and let the other controller read the session data.

Here is a silly example of what I mean:

Login contoller
PHP Code:
function login()
{
 
// Does authorisation check
 // finds user account has been banned
 
redirect('users/banned/'.$user_code);


Users contoller
PHP Code:
function banned($user_code)
{
 
// Get user details
 // get reasons user banned
$this->load->view('users/banned_view'$data);


Here the user id is passed from the login controller to the users controller showing the banned message.

But, the login controller would NOT call the banned controller to get data. As I said, bit of a silly example really, as you would not do this particular task in this way.

Hope that helps,

Paul.
Reply


Messages In This Thread
post data between controllers - by yinkoh - 12-01-2017, 12:57 AM
RE: post data between controllers - by PaulD - 12-01-2017, 06:09 AM
RE: post data between controllers - by yinkoh - 12-01-2017, 06:18 AM
RE: post data between controllers - by Martin7483 - 12-01-2017, 06:59 AM
RE: post data between controllers - by yinkoh - 12-01-2017, 07:06 AM
RE: post data between controllers - by Wouter60 - 12-01-2017, 08:11 AM
RE: post data between controllers - by yinkoh - 12-01-2017, 08:30 AM
RE: post data between controllers - by InsiteFX - 12-03-2017, 04:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB