Issues in loading models |
[eluser]Dvinge[/eluser]
Hello. I've been wandering on forums searching for a solution. I cannot use Models correctly when using $this. Code: Controller: It works when I'm using get_instance(); but without im getting this error: A PHP Error was encountered Severity: Notice Message: Undefined property: Forum::$forummodel Filename: controllers/forum.php Line Number: 16 Hope someone got a solution for this problem :-) EDIT: Code: $this->forum->forummodel->a('a'); // works too
[eluser]Derek Allard[/eluser]
Welcome to CI Dvinge. Your model looks fine (except the constructor note below also applies to it), but there are a few things we can clean up in your controller. Firstly, you don't need the constructor there, and I'd recommend you remove it (read Constructor-structor, what's your function?). Next up, you don't need to invoke the $CI super object in your controller. I'd make your whole controller this: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); *Notes: removed contructor, modified the opening '<?php' statement, removed '?>'
[eluser]Dvinge[/eluser]
Thanks for the cleanup, but the real problem is still alive. When I'm loading forummodel, it's not showing up in $this, but in $this->forum. I also tried a older version, but I'm getting the same issue.
[eluser]Edmundas KondraĊĦovas[/eluser]
Are you using a clean version of CodeIgniter?
[eluser]Derek Allard[/eluser]
[quote author="Dvinge" date="1299947375"]When I'm loading forummodel, it's not showing up in $this, but in $this->forum.[/quote] Wait, so when you use Code: $this->forummodel->a('foo'); Code: $this->a('foo'); If I'm reading that correct, then its not really the way CI is intended to be used. CI is intended that you need $this->{library}->{function}. You can rename it from 'forummodel' to 'forum' if you want when you load it, but you can't exclude it.
[eluser]Dvinge[/eluser]
[quote author="Derek Allard" date="1299964960"][quote author="Dvinge" date="1299947375"]When I'm loading forummodel, it's not showing up in $this, but in $this->forum.[/quote] Wait, so when you use Code: $this->forummodel->a('foo'); Code: $this->a('foo'); If I'm reading that correct, then its not really the way CI is intended to be used. CI is intended that you need $this->{library}->{function}. You can rename it from 'forummodel' to 'forum' if you want when you load it, but you can't exclude it.[/quote] No, i can't do $this->formmodel->a('foo'); as i tried to explain in the first post, but I wish to use $this->formmodel->a('foo'); I'm using a clean CI 2.0 yes. EDIT: Found the issue... I was autoloading a Forum class from my library which did something to my Forum controller i guess. Thanks for looking at it :-) |
Welcome Guest, Not a member yet? Register Sign In |