PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 9, 2022

[FIXED] CodeIgniter: how to pass values from a specific function to another one

 March 09, 2022     codeigniter, php     No comments   

Issue

I am trying to pass a value coming from a form using the method post from a function to another one.

class Send_value extends CI_Controller {

public function main_page() {
     $data['user'] = $this->input->post('fullName');
      ...
}


public function welcome_page(){
  //Now I would like to pass $data['user'] here.      

}
}

How can I pass it in the second function?


Solution

You need to pass parameter within that function and need to define that parameter as

class Send_value extends CI_Controller {

public function main_page() {
     $data['user'] = $this->input->post('fullName');
     echo $data['user']; //echoing value from post
     if(!empty($data)){
        $this->welcome_page($data); //passing data into another function
     } else {
        echo "Didn't get value from post";
     }
}


public function welcome_page($data = ''){
                           //^^ parameter set within function
    if(is_array($data) && count($data) > 0){
       print_r($data);
    } else {
       echo "No result found";
    }
  }
}


Answered By - Narendrasingh Sisodia
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing