CodeIgniter:如何将值从特定函数传递到另一个函数 [英] CodeIgniter: how to pass values from a specific function to another one

查看:61
本文介绍了CodeIgniter:如何将值从特定函数传递到另一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将使用方法发布的形式的值从一个函数传递给另一个函数。

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.      

}
}

如何在第二个函数?

推荐答案

您需要在该函数中传递参数,并将该参数定义为

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";
    }
  }
}

这篇关于CodeIgniter:如何将值从特定函数传递到另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆