使用Codeigniter 2.xx,如何在需要新HTTP请求的方法调用之间保留属性值?我试图避免多次获取和设置相同的数据。当前的例子: 型号:
class Plan_model extends Ci_model{
public $plan_id;
public function __construct()
{
parent::construct();
}
public function set_plan_id($plan_id)
{
$this->plan_id = $plan_id; //Becomes NULL with new http request, want to keep value
}
}
控制器:
class Plan extends Ci_controller{
public function __construct()
{
parent::__construct();
$this->load->model('plan_model');
}
public function set_plan_id()
{
$this->plan_model->set_plan_id(3)
redirect('/plan/get_plan_id');
}
public function get_plan_id()
{
$plan_id = $this->plan_model->plan_id; //produces NULL, Expecting 3
}
答案 0 :(得分:1)
您可能正在考虑使用会话来定义信息。
$this->session->set_userdata($plan_id);
以下是会话数据的链接:https://ellislab.com/codeigniter/user-guide/libraries/sessions.html