$CI =& get_instance();
这是非常重要的,引用赋值允许你使用原始的 CodeIgniter 对象,而不是创建一个副本。
然类库是一个类,那么我们最好充分的使用 OOP 原则,所以,为了让类中的所有方法都能使用 CodeIgniter 超级对象,建议将其赋值给一个属性:
class Example_library { protected $CI; // We'll use a constructor, as you can't directly call a function // from a property definition. public function __construct() { // Assign the CodeIg<strong>(本文来源gaodai#ma#com搞@@代~&码网</strong><pre>搞代gaodaima码
niter super-object $this->CI =& get_instance(); } public function foo() { $this->CI->load->helper('url'); redirect(); } public function bar() { echo $this->CI->config->item('base_url'); }}
相关推荐:
002 – PDO和MySQLi区别与选择
001 – PDO 用法详细解析
以上就是003 – CI在你的类库中使用 CodeIgniter 资源 的详细内容,更多请关注搞代码gaodaima其它相关文章!