Calling db from a view gives me an error - 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: Calling db from a view gives me an error (/showthread.php?tid=7641) |
Calling db from a view gives me an error - El Forum - 04-17-2008 [eluser]CARP[/eluser] Hi guys I'm loading DB class inside a view, and it is giving me an error PS: I just did the controller and its corresponding view. But I call DB from view only Code: $this->load->database(); gives: Fatal error: Call to a member function on a non-object in ****\system\application\views\clients\add.php on line 107 Calling db from a view gives me an error - El Forum - 04-17-2008 [eluser]garymardell[/eluser] Why are you trying to load the db class in the view. Why not just do it in the model/controller. Calling db from a view gives me an error - El Forum - 04-17-2008 [eluser]CARP[/eluser] Hi gazza After seeing lot of examples, etc. now I realized that it will work well in the model Now, an offtopic question: In which file I can declare a $var (constant) that I can get/call in the whole app? (views, controllers, models) Thanks Calling db from a view gives me an error - El Forum - 04-17-2008 [eluser]garymardell[/eluser] Again why do you need to? From your controller load the model. And pass a $var to say $this->modelName->getDetails($var); Then in the function return the data to your controller. Then to get the data into the view, $data['details'] = $this->modelName->getDetails($var); $this->load->view('viewname', $data); Then in your view your data can be found at $details . Calling db from a view gives me an error - El Forum - 04-17-2008 [eluser]CARP[/eluser] Hi gazza Yes, I did the db calling, etc. in the model, then passed data to controller, and controller passes data to the view. I got it I also added a constant with DEFINE(...); in the main index.php file, so both qs. are solved Calling db from a view gives me an error - El Forum - 04-17-2008 [eluser]xwero[/eluser] FYI the SVN has an constants file, specially added for defining constants so you don't have to do it in the index.php file Calling db from a view gives me an error - El Forum - 04-17-2008 [eluser]CARP[/eluser] [quote author="xwero" date="1208474236"]FYI the SVN has an constants file, specially added for defining constants so you don't have to do it in the index.php file[/quote] Awesome! will subscribe to official CI news so I learn when a new version is released |