我想要使用钩子设置几个常见变量。例如我有一个post_controller_constructor钩子,在这里我想执行一些逻辑来设置用户主文件夹:
public function post_controller_constructor() {
$home_folder = isset($_SESSION['hf']) ? $_SESSION['hf'] : NULL;
// Check whether the homefolder value has been set
$home_folder = isset($_SESSION['hf']) ? base_url($_SESSION['hf']) : base_url('default');
}
但是如何将生成的变量$ home_folder传回我的控制器?
答案 0 :(得分:5)
public function post_controller_constructor() {
$home_folder = isset($_SESSION['hf']) ? $_SESSION['hf'] : NULL;
// Check whether the homefolder value has been set
$home_folder = isset($_SESSION['hf']) ? base_url($_SESSION['hf']) : base_url('default');
$CI =& get_instance();
$CI->home_folder = $home_folder;
}
会这样做。