如何在我自己创建的库codeigniter中加载模块

时间:2013-09-28 10:20:26

标签: codeigniter

 class Mylib
 {
    function show_lib()
    {

       $obj=& get_instance();
       $obj->load->module(‘login_check’);
       $var=$obj->login_check->get_all_table_data();
       print_r($var);
    }
 }

错误: - 致命错误:调用未定义的方法CI_Loader :: module()

4 个答案:

答案 0 :(得分:1)

我希望这会起作用 - >检查此代码

class Mylib
{   
  function show_lib()
  {
      protected $ci; 
     $this->ci = &get_instance();
     $this->ci->load->library(‘login_check’);
     $var=ci->load->login_check->get_all_table_data();     
     return $var;
  } 
}

答案 1 :(得分:0)

不是模块,它是一个库

使用:

$this->load->library();

答案 2 :(得分:0)

在CI中使用模块称为HMVC - 分层模型视图控制器。 CI有一个漂亮的模块化扩展,可以使用 - Modular Extensions - HMVC

通过使用此扩展,您可以在CI中创建和使用模块。

设置HMVC扩展后,您可以从控制器中调用模块。

$controller = $this->load->module('module_name/controller_name');
echo $controller->method();

很少有入门教程:

http://net.tutsplus.com/tutorials/php/hvmc-an-introduction-and-application/ http://www.extradrm.com/blog/?p=744

答案 3 :(得分:0)

如果您使用的是codeigniter 3,则需要使用Codeigniter Object来加载模块,帮助程序..等等。将Codeigniter对象分配给变量并使用它。 $CI =& get_instance()示例代码

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class CustomLibrary{

    public $random_number;

    public function __construct(){

        $CI =& get_instance();
        $CI->load->helper('string');
    }
}

有关此次访问的详情,请http://www.webnsyntax.com/

相关问题