Error in $this->db->get() |
[eluser]Roey[/eluser]
Hello everyone. I try to build a site with CodeIgniter framework. when i try to use the Code: $this->db->get('animals'); Quote:Fatal error: Call to a member function get() on a non-object in C:\wamp\www\ci\system\application\controllers\register.php on line 14 I need help with that. please tell me if you need more code from my project. thank you
[eluser]kaejiavo[/eluser]
you have to load the database library in autoload.php or in your controller $this->load->library('database') Marco
[eluser]Roey[/eluser]
here is my autoload file. as you can see i load the db. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); And when i try with the line: Code: $this->load->library('database'); i also get an error: Quote:An Error Was Encountered when i checked i dont have "database.php" in my "libraries" folder. maybe this is the problem?
[eluser]WanWizard[/eluser]
The fact that you attempt to load it doesn't mean it is. Loading can also fail if you have problems connecting to the database, if you database config is not correct, or if you don't have sufficient rights. Check your CI logs (set the log threshold to 4 to see all messages).
[eluser]Roey[/eluser]
well. i'm new to CodeIgniter and i dont know how/where to set this and check. anyway, when i try the "scaffolding" its working fine. can you tell me how to check the CI logs and how to set the log threshold to 4? thanks
[eluser]WanWizard[/eluser]
Scaffolding is deprecated, and removed in CI 2.0. Don't have your apps rely on it, otherwise you won't be able to upgrade. If that works, you DB seems ok, so we'll need to see your code to figure out what's wrong. You change the log (and lots of other info) in config/config.php. I suggest you take a day or so to go through the user guide. It's excellent, and explains all these things...
[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...mples.html It's not: Code: $this->load->library('database'); Code: $this->load->database(); In autoload, however, it does belong in libraries. There's even an example of this in the file. There's no "core" autoload section, you would have had to add it yourself, and I'm not sure why you'd do that. Code: /*
[eluser]Unknown[/eluser]
I autoloaded the database library but I still get that non-object error mentioned above when I try to use $this-db in a model. When I do it in a controller everything works well. What could I be doing wrong? My model looks like this: Code: <?php |
Welcome Guest, Not a member yet? Register Sign In |