CI中在视图层直接调用library

  在CodeIgniter中,一般来说,是要在控制层中调用library的,但假如要在
视图层调用library的话,比如:
   $this->load->library(‘some_library’);

这样调用,按道理说是违反MVC的,但假如要确实调用的话,上面调用也是错误的,会
显示:
   PHP Fatal error:  Call to a member function some_library_function() on a non-object in …….php file.
   而要如下方式调用:
   $ci_obj = & get_instance();
$ci_obj->load->library('some_library');
$ci_obj->some_library->some_library_function();


  或者写成方法:
  function load_library($library_name) {

$ci = & get_instance();
$ci->load->library($library_name);
return $ci->$library_name;

}

你可能感兴趣的:(library)