PHP Error = Undefined property: User::$view_data |
[eluser]MikeL85[/eluser]
Hi. I'm a neewbie to MVC Framworks, CodeIgnitor, OOP - in fact I'd never even heard the term "PHP Framework" until a couple of days ago. Anywayyy..... I have tried to follow a simple tutorial but have fallen at the first hurdle. I have tried to follow this guy as close I could. I got told by a friend to replace "Controller" with "CI_Controller" but that hasn't stopped the following errors from appearing; A PHP Error was encountered Severity: Notice Message: Undefined property: User::$view_data Filename: controllers/user.php Line Number: 19 And: A PHP Error was encountered Severity: Notice Message: Undefined variable: base_url Filename: views/view_register.php Line Number: 10 Here is my user.php code: Code: <?php and also my view_register.php code: Code: <html> It's so off-putting when things like this happen. Please help to stop me from giving up and chucking all this codeignitor stuff in the trash!
[eluser]Glazz[/eluser]
hmm try this: Code: class User extends CI_Controller{ See if it works..
[eluser]MikeL85[/eluser]
Thanks. That solution partly works. If I leave in the __construct function (or the User() function for that matter) I get a blank page on loading. If I leave those functions out I still get the second error; A PHP Error was encountered Severity: Notice Message: Undefined variable: base_url Filename: views/view_register.php Line Number: 10 But declaring $view_data as an array got rid of one error so well done there...
[eluser]Glazz[/eluser]
The construct function is called automatically if you don't use the construct the base_url will not be set so you can use on your view, thats why you are getting the undefined error..
[eluser]CroNiX[/eluser]
Why do you need to pass base_url(), which is globally available? Just use it directly in your view. You are mixing php4 and php5 syntax. In php4, you name a class method after the name of the class to create the constructor. In php5, you just use __construct(). So, create the __construct() and move all of your code from the user() method into that, but don't use both together. PHP5 properties don't get declared using "var". Declare them by their visibility, like "public", "private", "protected", etc. public $view_data; instead of var $view_data;
[eluser]CroNiX[/eluser]
Code: function __construct() Should also be: Code: function __construct() |
Welcome Guest, Not a member yet? Register Sign In |