[英]Codeigniter MY_loader is not loading
我正在嘗試在CodeIgniter中創建頁眉/正文/頁腳模板,類似於以下內容: CodeIgniter中的頁眉和頁腳
我的代碼存儲在\\ application \\ core \\ MY_loader.php中:
<?php
class MY_Loader extends CI_Loader {
public function load_template($template_name, $vars = array(), $return = FALSE)
{
if($return):
$content = $this -> view('templates/header', $vars, $return);
$content .= $this -> view($template_name, $vars, $return);
$content .= $this -> view('templates/footer', $vars, $return);
return $content;
else:
$this -> view('templates/header', $vars);
$this -> view($template_name, $vars);
$this -> view('templates/footer', $vars);
endif;
}
}
?>
我的控制器代碼存儲在application \\ controllers \\ managers.php中:
class Managers extends CI_Controller {
function login()
{
$this -> load -> load_template('managers/login');
}
}
當我瀏覽到BASE_URL / managers / login時,出現以下錯誤:
調用未定義的方法CI_Loader :: load_template()
我對此的解釋是,系統未使用MY_Loader擴展CI_Loader,而是完全忽略了MY_Loader。 當我在XAMPP下運行該安裝程序時,此安裝程序正在該站點的本地安裝上運行,但是在將該站點移植到Web主機后,該設置停止了工作。 我不記得更改CI配置(盡管可能有),也不知道這是否是由於新主機上的配置問題引起的。
我正在尋找有關阻止MY_loader擴展CI_loader的任何指導。 我沒有找到任何類似的報告; 我發現與MY_loader相關的所有其他問題均假定該替代已在起作用。
該文件必須稱為“ MY_Loader.php”-區分大小寫,並且與“ MY_loader.php”不同。
與目前唯一的答案相反,“ My_loader.php”也不起作用,因為subclass_prefix
與庫名是分開應用的。
最簡單的例子是:
$libraryName = 'loader';
$className = ucfirst(strtolower($libraryName));
$className = config_item('subclass_prefix').$className;
$fileName = $className.'.php';
將其另存為MY_Loader.php(由於其他朋友的建議,“ L”也必須是大寫字母)
public function load_template($template_name, $vars = array(), $return = FALSE)
{
$CI = & get_instance();
if($return):
$content = $CI->load->view('templates/header', $vars, $return);
$content .= $CI->load->view($template_name, $vars, $return);
$content .= $CI->load->view('templates/footer', $vars, $return);
return $content;
else:
$CI->load->view('templates/header', $vars);
$CI->load->view($template_name, $vars);
$CI->load->view('templates/footer', $vars);
endif;
}
}
?>
希望我能幫上忙。 祝你今天愉快。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.