如何在 codeigniter 中将数组从一个 class 控制器传递到另一个控制器

how to pass an array from one class controller to another in codeigniter

我有两个控制器,例如控制器文件夹中的 doc.php、user.php 和视图文件夹中的 registration.php,它们都有一个注册表。 我想通过 user.php将注册信息 从 registration.php 传递到 doc.php 控制器。 我怎样才能做到这一点?需要帮助。

在 CodeIgnitor 中,您通常使用会话对象在控制器之间传递数据。例如:

// initialise the session object
$this->load->library('session');

// save the array to the session
$this->session->set_userdata('reg_info', $reg_info);

// retrieve the array in the other controller:
$this->session->userdata('reg_info');

有关 CodeIgnitor 会话对象的更多信息,请参见 docs

你的 codeigniter 版本是多少? 2.x 或 3.x ?

尝试使用会话来保存你的数组。

要在控制器构造函数中手动初始化会话 class,请使用此方法:

$this->load->library();

加载后,会话库对象将可用:

$this->session

您可以使用以下代码设置会话名称:

$this->session->your_session_name;

使用它在您的会话中添加项目:

$this->session->your_session_name('item_one');

要检索您的会话,请使用此代码:

$this->session->your_session_name;

Check this 对于 CodeIgniter 3.X

Check this 对于 CodeIgniter 2.X