codeigniter返回“Message:Undefined property:Welcome :: $ load”试图加载助手lib [英] codeigniter returns "Message: Undefined property: Welcome::$load" trying to load helper lib
问题描述
背景信息
我刚刚安装了CI的新副本,并修改了欢迎控制器以包含url助手,方法 base_url
。然后尝试从 home.php
问题: $ b调用此方法$ b我得到以下错误消息:
消息:未定义属性:Welcome :: $ load
文件名:controllers / welcome.php
代码:
$ b这是我欢迎控制器现在的样子:
class Welcome extends CI_Controller {
public function __construct()
{
$ this-> load-> helper('url');
}
public function index()
{
$ this-> load-> view('home');
}
}
视图如下所示:
<!DOCTYPE html>
< html lang =en>
< head>
< meta http-equiv =X-UA-Compatiblecontent =IE = Edge/>
< meta charset =utf-8>
< meta name =viewportcontent =width = device-width>
< meta name =descriptioncontent =>
<! - Le styles - >
< title>测试网站< / title>
< script>
var BASEPATH =<?php echo base_url();?>;
< / script>
< link href =<?php echo base_url('assets / css / bootstrap.min.css')?> rel =stylesheet>
< link href =<?php echo base_url('assets / css / navbar.css')?> rel =stylesheet>
< / head>
系统正在死在控制器的构造函数中,我试图加载库...
我到目前为止做了什么:
- 阅读手册。 http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
尝试在config / autoload.php中包含url库,如下所示:
code> $ autoload ['helper'] = array('url');
$ b b但我仍然得到的错误。
任何建议?
谢谢。
解决方案您忘记了一件关键的事情;
code> class Welcome extends CI_Controller {
public function __construct()
{
parent :: __ construct();
$ this-> load-> helper('url');
}
public function index()
{
$ this-> load-> view('home');
}
}
parent :: __结构
。如果你不这样做;当您覆盖自己的控制器中的__construct时,Controller不会继承它的抽象层。
只要不重写
__ construct
一切OK。它只会发生在你覆盖它。你没有加载
功能,因为Welcome类是空的(没有继承),即使它扩展了CI_Controller
(但使用__ contstruct
覆盖)。Background Information
I just installed a fresh copy of CI and modified the welcome controller to include the url Helper so I can call the method
base_url
. I then try to call this method fromhome.php
Problem: I'm getting the following error message:
Message: Undefined property: Welcome::$load Filename: controllers/welcome.php
Code:
This is what my welcome controller now looks like:
class Welcome extends CI_Controller { public function __construct() { $this->load->helper('url'); } public function index() { $this->load->view('home'); } }
The view looks like this:
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge"/> <meta charset="utf-8"> <meta name="viewport" content="width = device-width"> <meta name="description" content=""> <!-- Le styles --> <title>test site</title> <script> var BASEPATH = "<?php echo base_url(); ?>"; </script> <link href="<?php echo base_url('assets/css/bootstrap.min.css')?>" rel="stylesheet"> <link href="<?php echo base_url('assets/css/navbar.css')?>" rel="stylesheet"> </head>
The system is dying on the line in the controller's constructor where i try to load the library...
What I've done so far:
- Read the manual. http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
Tried to include the url library in the config/autoload.php like so:
$autoload['helper'] = array('url');
But I'm still getting the error. Any suggestions?
Thanks.
解决方案You forgot a crucial thing;
class Welcome extends CI_Controller { public function __construct() { parent::__construct(); $this->load->helper('url'); } public function index() { $this->load->view('home'); } }
The
parent::__construct
. If you don't do that; the Controller will not inherit it's abstract layer when you override the __construct in your own controller.As long as you don't override your
__construct
it's all ok. It only happens when you override it. You don't have theload
functionality because the Welcome class is empty (no inheritance), even if it extends theCI_Controller
(but with a__contstruct
override).这篇关于codeigniter返回“Message:Undefined property:Welcome :: $ load”试图加载助手lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!