Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在codeigniter3中将数据从控制器传递到自定义挂钩_Php_Codeigniter_Codeigniter 3_Hmvc - Fatal编程技术网

Php 如何在codeigniter3中将数据从控制器传递到自定义挂钩

Php 如何在codeigniter3中将数据从控制器传递到自定义挂钩,php,codeigniter,codeigniter-3,hmvc,Php,Codeigniter,Codeigniter 3,Hmvc,我的应用程序中有一个hooks类,我想从控制器发送会话数据。但我在传递数据时遇到了问题。我不知道是否有可能将数据从控制器发送到钩子 下面是一个hooks类的示例,代码如下 function switchUser() { $CI = &get_instance(); $user_id=$CI->uid; if ($user_id == 'client') { echo "hello"; } } 这是我的控制器 class

我的应用程序中有一个hooks类,我想从控制器发送会话数据。但我在传递数据时遇到了问题。我不知道是否有可能将数据从控制器发送到钩子

下面是一个hooks类的示例,代码如下

function switchUser()
{
    $CI = &get_instance();    
    $user_id=$CI->uid;

    if ($user_id == 'client') {
       echo "hello";
    }   
}
这是我的控制器

class Client_Controller extends MX_Controller
{
    public $uid;
    function __construct($dbase=array())
    {
        parent::__construct();

        $this->uid=$this->session->userdata("uid");
    }
}
在hooks.php文件中,我有以下代码

$hook['pre_controller'] = array(
    'function' => 'switchDatabase',
    'filename' => 'switchDatabase.php',
    'filepath' => 'hooks'
);

请帮我解决这个问题。

希望这能帮助您:

switchUser
方法中

用这个

$CI->session->userdata("uid") 
而不是这个

$CI->uid 
整个代码应如下所示:

function switchUser()
{
    $CI = &get_instance();    
    $user_id = $CI->session->userdata("uid") 

    if ($user_id == 'client') {
       echo "hello";
    }   
}

更多信息:

在switchUser方法中使用此
$CI->session->userdata(“uid”)
而不是此
$CI->uid
,非常感谢