This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

✨ Vultr and Linode are back on Cloudways! VIEW PLANS→

Pass Data From One Function To Another In Same Codeigniter Controller

Updated on June 3, 2021

< 1 Min Read

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.

pass data between functions in CodeIgniter

Here is what the Model looks like:

Model

function getResponse($gettingresponse)

{

$enrollresponse=$gettingresponse['sendresponse'];

return $enrollresponse;

}

The Controller is as follows:

Controller

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

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

Stop Wasting Time on Servers

Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.

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

Share your opinion in the comment section. COMMENT NOW

Share This Article

Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. Besides his work life, he loves movies and travelling.

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now