Categories: Learn CodeIgniter Tutorials, Tips And GuidesLearn PHP Tutorials, Tips And Guides

Pass Data From One Function To Another In Same Codeigniter Controller

Reading Time: 1 minute

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:


function getResponse($gettingresponse)



return $enrollresponse;


The Controller is as follows:


public function Register()




   if($_POST) {














public function token($data=array())







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


<?php echo form_input(array('name'=>'source','readonly'=>'true','value'=>$resposeflag)); ?>


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 built on any PHP MySQL Hosting. If you need help, do leave a comment below.

Shahroze Nawaz :Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. He’s always in search of new frameworks and methods to implement them. Besides his coding life, he loves movies and playing soccer with friends. You can email him at shahroze.nawaz@cloudways.com