Reputation: 3
I'm trying to build a simple controller for a registration form as seen on a Youtube video, but for some reason, I'm getting an error with a piece of code that works for him.
<?php
class User extends CI_Controller {
function __User() {
parent::CI_Controller();
$this->view_data['base_url'] = base_url();
}
function index() {
$this->register();
}
function register() {
$this->load->view('view_register', $this->view_data);
}
}
That's what I currently have, with:
$autoload['helper'] = array('url');
set in autoload.php.
I've tried to search around for answers to this question, but nothing appears to work and the only solution I've seen was for a slightly different problem. Does anyone have any idea as to what could be wrong?
Also, if it helps any, this is the exact error message:
Severity: Notice
Message: Undefined property: User::$view_data
Filename: controllers/user.php
Line Number: 19
Upvotes: 0
Views: 4181
Reputation: 1523
It looks like they are trying to reference a field called view_data
. Adding this would fix it:
class User extends CI_Controller
{
private $view_data = array();
}
Upvotes: 1