Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Model MY_Loader Codeigniter中的负载模型_Model_Load_Codeigniter 2 - Fatal编程技术网

Model MY_Loader Codeigniter中的负载模型

Model MY_Loader Codeigniter中的负载模型,model,load,codeigniter-2,Model,Load,Codeigniter 2,如何在“application/core”目录下的my_Loader.php文件中加载模型 我试图将我的加载程序视图分组到my_加载程序文件中,以便更方便地加载视图。我想将动态值传递到标题以自定义标题输出 我的代码如下所示: private $ci; public function __construct() { parent::__construct(); // Initiate instance $this->ci =& get_instanc

如何在“application/core”目录下的my_Loader.php文件中加载模型

我试图将我的加载程序视图分组到my_加载程序文件中,以便更方便地加载视图。我想将动态值传递到标题以自定义标题输出

我的代码如下所示:
private $ci;   

public function __construct()
{
    parent::__construct();

    // Initiate instance
    $this->ci =& get_instance();

    // Load model
    $this->ci->load->model('My_loader_model');

}   

public function template($template_name, $vars = array(), $return = FALSE)
{
    $data_header['inbox_messages'] = $this->ci->My_loader_model->inbox_messages_count();

    $content  = $this->view('header', $data_header, $return);
    $content .= $this->view($template_name, $vars, $return);
    $content .= $this->view('footer', $vars, $return);

    if ($return)
    {
        return $content;
    }
}

}

在core文件夹中创建一个包含CI_Controller的commondata扩展名的文件。 将通用模型设置为自动加载
function getSettingData($id)
{
        return $this->common->selectbyid($id);
}
}

像这样将此文件包含到myLoader中 /** */application/core/MY_Loader.php * */ 类MY_Loader扩展CI_Loader{

function __construct() {
    parent::__construct();
}

public function template($template_name, $vars = array(), $return = FALSE) {
    $requestUri = $_SERVER['REQUEST_URI'];
    include(dirname(__FILE__)."/commondata.php");
    $settingdata = new commondata();
    $vars['companyname'] = $settingdata->getSettingData(1);
    $content = "";

        $content = $this->view('templates/header_admin', $vars, $return);
        $content .= $this->view($template_name, $vars, $return);
        $content .= $this->view('templates/footer_admin', $vars, $return);



        return $content;
}

}

您可以在autoload.php中自动加载模型。为什么在elseHave将它添加到$autoload['model']=array('my_loader_model')的某些地方,你在做它时会遇到麻烦;在autoload.php中似乎仍然没有加载,所以我可以从my_Loader.php(在dir“core”中)与它集成。我添加了
log_消息(“debug”,“您的模型已加载”)
到模型构造函数,查看是否加载了它,而没有加载。有什么建议吗?现在开始工作了。自动加载阵列中型号名称的大写字母。谢谢你的帮助!请删除此问题,因为您既没有答案也不再需要。还是我加一个答案让你接受?