how to pass a variable from one controller to the other in Code igniter

后端 未结 6 926
攒了一身酷
攒了一身酷 2021-02-05 21:25

I have just started learning Code Igniter .

I want to know how can I pass a variable from one controller(first_cont.php) to other controller (second_cont.php) ?

6条回答
  •  渐次进展
    2021-02-05 22:11

    Ok, here is something about MVC most will readily quote:

    A Controller is for taking input, a model is for your logic, and, a view is for displaying.

    Now, strictly speaking you shouldn't want to send data from a controller to another. I can't think of any cases where that is required.


    But, if it is absolutely needed, then you could simply use redirect to just redirect to the other controller.

    Something like:

    // some first_cont.php code here
    redirect('/second_cont/valuereciever/value1')
    
    
    // some second_cont.php code here
    public function valureciever($value){
        echo $value; // will output value1
    }
    

提交回复
热议问题