Codeigniter: Call to a member function view() on null
13,431
If you have use update Ci than try it :
function __construct()
{
parent::__construct();
}
Author by
user6891871
Updated on June 04, 2022Comments
-
user6891871 almost 2 years
I just started a simple php project by using codeigniter framework and my steps are following.
Create a controller named
user.php
.After that created a view
articles_list.php
inside the sub directorypublic
.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: