本文介绍了使用CI钩子设置公共变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个常见的变量,我想使用钩子设置。例如我有一个post_controller_constructor钩子,在这里我想执行一些逻辑设置用户主文件夹:
I have several common variables which I want to set using a hook. For example I have a post_controller_constructor hook, inside this I want to perform some logic to set the users home folder:
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传递回我的控制器? / p>
But how do I pass the resulting variable $home_folder back to my controllers?
推荐答案
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;
}
会这样做。
这篇关于使用CI钩子设置公共变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!