【发布时间】:2019-11-17 11:56:03
【问题描述】:
我正在使用CodeIgniter 4 的最新“主”分支
我有一个试图自动加载的库。实际上,我希望拥有“一个”index.php(具有元、基本 html 结构等),通过它我可以通过“模板”库加载视图。
我的库文件:(~/app/Libraries/Template.php)
//class Template extends CI_Controller
class Template {
/* This throws an error, but I will open up a separte thread for this
public function __construct() {
parent::__construct();
}
*/
public function render($view, $data = array()) {
$data['content_view'] = $view;
return view('layout/index', $data);
}
}
我还设置了一个控制器:
class Locations extends BaseController
{
public function index()
{
return $this->template->render("locations/index", $view_data);
//return view('locations/index');
}
//--------------------------------------------------------------------
}
在 ~/app/Config/ 我添加了我的库
$classmap = [
'Template' => APPPATH .'/Libraries/Template.php'
];
我收到以下错误:
Call to a member function render() on null
我做错了什么导致我的库无法加载?
【问题讨论】:
-
CodeIgniter 4 未发布。不利于生产。你为什么用它?
-
测试一下:)
标签: php autoload codeigniter-4