A controller often comprises of several functions and often the module’s logic demands passing data between the various functions of the Controller. This is a common enough scenario in many Codeigniter projects. In this tutorial, I will demonstrate how you could pass data between two functions within the same Controller in CodeIgniter. In addition, I will show this data in the View.

Here is what the Model looks like:
Model
|
1 2 3 4 5 6 7 8 9 |
function getResponse($gettingresponse) { $enrollresponse=$gettingresponse['sendresponse']; return $enrollresponse; } |
The Controller is as follows:
Controller
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
public function Register() { $this->load->view('firstview'); $this->load->view('secondview'); if($_POST) { $gettingresponse=array( 'sendresponse'=>$_POST['source'], 'receiverresponse'=>$_POST['destination'] ); $registration_confirm=$this->systemModel->responselogin($gettingresponse); $resposeflag=$this->systemModel->getEmail($gettingresponse); $data['resposeflag']=$gettingresponsevalue; if($registration_confirm){ $this->token($data); } } $this->load->view('thirdview'); } public function token($data=array()) { $this->load->view('firstview'); $data['resposeflag']; $this->load->view('token',$data); $this->load->view('thirdview'); } |
The following View shows the data that has been passed between the functions of the Controller.
You might be interested in: How To Pass Data From Controller To View In CodeIgniter
View
|
1 |
<?php echo form_input(array('name'=>'source','readonly'=>'true','value'=>$resposeflag)); ?> |
Conclusion
In this tutorial, I have discussed how to pass data from one function to another in a Controller. You could easily extend this idea within your Codeigniter projects. If you need help, do leave a comment below.
Create PHP websites without the worry of server management.
Deploy your PHP app on optimized PHP hosting servers.