Om3ga
Om3ga

Reputation: 32823

having issue while calling load function inside codeigniter

I am loading view in codeigniter and calling $this->load->view('login'); in my controller. But it gives me following error

 Severity: Notice

 Message: Undefined property: Login::$load

 Filename: controllers/login.php

 Line Number: 6

 Fatal error: Call to a member function view() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/membership_system/application/controllers/login.php on line 6

Here is my controller

 class Login extends CI_Controller {

public function index() {
    $this->load->view('login'); //<-- error is on this line
}

public function login() {

}

public function register() {

}
}

how can I solve this problem?

UPDATE

When I change class name from Login to Something_login then this works but only with Login it gives me above error. Why?

Upvotes: 0

Views: 130

Answers (2)

Narf
Narf

Reputation: 14752

This is a PHP "limitation" - it is a backwards compatibility feature for PHP 4, where you don't have __construct() and a method name matching the class name is executed as a class constructor.

You probably could go around that if you put a PHP5-style constructor to be called instead, just make sure to call the parent one in it:

public function __construct()
{
     parent::__construct();
}

Also, this wouldn't be the case if you're inside a namespace, but CodeIgniter currently doesn't utilize those for compatibility with older PHP versions.

Upvotes: 0

Thanh Nguyen
Thanh Nguyen

Reputation: 5342

the name of function must be different from your Class name.

Upvotes: 1

Related Questions