首页 > 解决方案 > 如何在 custom_loader 中加载库?

问题描述

我试图弄清楚如何从位于 /application/core/SACC_Loader.php 的自定义加载器中加载会话、ftp 等库

到目前为止,我已经尝试了正常的方法,并使用 get_instance() 但无济于事。

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class SACC_Loader extends CI_Loader {
    private $lang = null;
    public function template($template_name, $vars = array(), $return = FALSE, $ajax = FALSE)
    {
        /* Prepare default values always loaded unless it's an Ajax request */

        $vars = $this->static_content($vars);
        if($return){
            $content  = $this->view('components/header', $vars, $return);
            $content .= $this->view($template_name, $vars, $return);
            $content .= $this->view('components/footer', $vars, $return);

            return $content;
        } else {
            $this->view('components/header', $vars);
            $this->view($template_name, $vars);
            $this->view('components/footer', $vars);
        }
    }

还是我接近这一切都错了?我的想法是使用自定义加载器始终将所需数据携带到正在运行的任何控制器中,而不必在每个控制器中加载模型,因为我已经为所有页面使用了自定义加载器来加载模板,而不仅仅是单个/多个视图每个控制器方法。

我的意思是这行得通,但感觉是重复的。

标签: phpcodeigniter

解决方案


推荐阅读