New CI User - need assistance with Model issue please. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: New CI User - need assistance with Model issue please. (/showthread.php?tid=40580) Pages:
1
2
|
New CI User - need assistance with Model issue please. - El Forum - 04-12-2011 [eluser]Mirge[/eluser] Controller (site.php): Code: <?php Model (site_model.php): Code: <?php View (home.php): Code: <p>My view has been loaded</p> --- This works, but it took a TON of google'ing to figure out this fix... and I don't understand why it's necessary? Please help me understand what is actually happening here. If you look at the model code, you'll notice: $this->CI = get_instance(); Without this (and obviously w/out referencing it in the code following it), it breaks with a Fatal error... Fatal error: Call to a member function get() on a non-object Any reason why exactly? I was following the nettuts videos by Jeffrey and ran into this at the end. Using CodeIgniter 2.0.2, PHP 5.3... thanks for the help! New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]InsiteFX[/eluser] Did you try to autolaod the database in application/config/autoload.php ? You can also autoload your Model. InsiteFX New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]Mirge[/eluser] [quote author="InsiteFX" date="1302715972"]Did you try to autolaod the database in application/config/autoload.php ? You can also autoload your Model. InsiteFX[/quote] Sorry, forgot to mention that. Yes, I autoloaded DB. Did not autoload model... following that jeffrey way day 1 tutorial, he didn't.... so I didn't. I commented out $this->CI->load->db(...) and it still works of course. I just don't understand why I have to use get_instance() in the model? Am I doing something wrong? New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]InsiteFX[/eluser] You should not have to use get_instance in the model, I just wrote a model last night and did not have to use get_instance. If your creating a library then some times you need get_instance. Model: Code: <?php InsiteFX New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]Mirge[/eluser] [quote author="InsiteFX" date="1302725864"]You should not have to use get_instance in the model, I just wrote a model last night and did not have to use get_instance. If your creating a library then some times you need get_instance. Model: Code: <?php InsiteFX[/quote] Thanks, Insite... I greatly appreciate your help. Are you using CodeIgniter Reactor 2.0.2? Just making sure. I can't figure out why it won't work for me. using XAMPP.. maybe I should try my paid hosting account instead to test. New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]InsiteFX[/eluser] Yes I am using CodeIgniter Reactor 2.0.2 on Windows 7 Pro x64-bit and XAMPP 1.7.3 Give me a little time, I'll copy what you have here and see if I can find out whats wrong. I already have a test database so I can use that... InsiteFX New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]Atas[/eluser] put this on top of the index.php ini_set('display_errors', '1'); New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]Mirge[/eluser] [quote author="InsiteFX" date="1302726585"]Yes I am using CodeIgniter Reactor 2.0.2 on Windows 7 Pro x64-bit and XAMPP 1.7.3 Give me a little time, I'll copy what you have here and see if I can find out whats wrong. I already have a test database so I can use that... InsiteFX[/quote] Exact same setup as me, but using XAMPP 1.7.4... though I imagine that has nothing to do w/ my issue. Thanks again for the help! Just started playing w/ codeigniter, and ran into this issue, discouraging... but the benefits of using CI far out-weigh this hurdle I can already tell. My 'test' table simply contains: id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL, title VARCHAR(255) NOT NULL New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]Mirge[/eluser] [quote author="Atas" date="1302726710"]put this on top of the index.php ini_set('display_errors', '1');[/quote] ini_set('display_errors', 'on'); ini_set('display_startup_errors', 'on'); error_reporting(E_ALL); No new information... just same error. New CI User - need assistance with Model issue please. - El Forum - 04-13-2011 [eluser]InsiteFX[/eluser] @Mirge, Ok, I just ran your code and it works here! Controller: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Model: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); View: Code: <!DOCTYPE html> InsiteFX |