Codeigniter:在null上调用成员函数view() [英] Codeigniter: Call to a member function view() on null

查看:428
本文介绍了Codeigniter:在null上调用成员函数view()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用codeigniter框架开始一个简单的php项目,我的步骤如下。


  1. 创建一个名为


  2. 之后创建视图 articles_list.php


  3. 在控制器中加载视图后, / p>


但调用null上的成员函数view
这个我使用3.2.1版本的codeigniter框架。



我是这个框架中的初学者。请告诉我我错了。



user.php(Controller)

  ;?php 
类用户扩展MY_Controller {
public function __construct(){
parent :: __ construct();
}
public function index(){
echolist articles;
$ this-> load-> view('public / articles_list');
}
}
?>

articles_list.php(检视)

 < html> 
< head>
< title>文章列表< / title>
<! - < link rel =stylesheettype =text / csshref =http://localhost/codeigniter/assets/css/bootstrap.min.css> - > ;
< / head>
< body>
< p> hello< / p>
< / body>

< / html>提前感谢。



错误如下:

this ..



列表文章
遇到PHP错误

 严重性:Notice 

消息:未定义属性:User :: $ load

文件名:controllers / user.php

行号: 8

Backtrace:

文件:C:\ xampp\htdocs\codeigniter\application\controllers\user.php
Line:8
功能:_error_handler

文件:C:\ xampp\htdocs\codeigniter\index.php
行:315
功能:require_once


致命错误:调用成员函数view()on C:\ xampp\htdocs\codeigniter\application\controllers\user.php on line 8
遇到PHP错误

严重性:错误

消息:调用null上的成员函数view()

文件名:controllers / user.php

行号:8

Backtrace:


解决方案

将控制器另存为User.php。请注意, U 大写。在codeigniter版本3.1.0及以上版本中,控制器和模型的文件名需要保存为 U ser.php。
也将 MY_Controller 更改为 CI_Controller



希望这有助于:)


I just started a simple php project by using codeigniter framework and my steps are following.

  1. Create a controller named user.php.

  2. After that created a view articles_list.php inside the sub directory public.

  3. After that loaded view in controller.

but getting fatal error call to a member function view() on null. for this i am using 3.2.1 version of codeigniter framework.

I am beginner in this framework.Please tell me where I am wrong.

user.php (Controller)

<?php
class User extends MY_Controller{
public function __construct() {        
parent::__construct();
}
public function index(){
    echo "list articles";
    $this->load->view('public/articles_list');
}
}
?> 

articles_list.php (View)

<html>
<head>
<title>Article List</title>
<!--<link rel="stylesheet" type="text/css" href="http://localhost/codeigniter/assets/css/bootstrap.min.css">-->
</head>
<body>
<p>hello</p>
</body>

</html>

Thanks in advance.

Error like this..

list articles A PHP Error was encountered

Severity: Notice

Message: Undefined property: User::$load

Filename: controllers/user.php

Line Number: 8

Backtrace:

File: C:\xampp\htdocs\codeigniter\application\controllers\user.php
Line: 8
Function: _error_handler

File: C:\xampp\htdocs\codeigniter\index.php
Line: 315
Function: require_once


Fatal error: Call to a member function view() on null in C:\xampp\htdocs\codeigniter\application\controllers\user.php on line 8
A PHP Error was encountered

Severity: Error

Message: Call to a member function view() on null

Filename: controllers/user.php

Line Number: 8

Backtrace:

解决方案

Save your controller as User.php. Note that U is capitalized. In codeigniter versions 3.1.0 and above versions, file names of controllers and models needed to be saved like User.php. Also change MY_Controller to CI_Controller

Hope this helps :)

这篇关于Codeigniter:在null上调用成员函数view()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆