CodeIgniter Forums
Run query in view rather than controller - 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: Run query in view rather than controller (/showthread.php?tid=35762)



Run query in view rather than controller - El Forum - 11-10-2010

[eluser]Unknown[/eluser]
Hi,

I need to execute a query in view rather than in controller. Can any body help me please how to call. If I call it gives the error message

Severity: Notice

Message: Undefined property: CI_Loader::$db

Filename: views/floorplan.php

Line Number: 57


Run query in view rather than controller - El Forum - 11-10-2010

[eluser]prestondocks[/eluser]
Could you provide the reason for running the query in the View. You are working outside of the Model, View, Controller framework if you put data access or too much logic in your views.

We may be able to help you put the query back in the model where it should be if we understand the what you are trying to do.

Simon


Run query in view rather than controller - El Forum - 11-10-2010

[eluser]danmontgomery[/eluser]
Code:
$CI =& get_instance();
$CI->db->...



Run query in view rather than controller - El Forum - 11-10-2010

[eluser]smilie[/eluser]
+1 for prestondocks - do not mix queries in your view :-) Follow MVC moddel Smile

Cheers,
Smilie


Run query in view rather than controller - El Forum - 11-10-2010

[eluser]Juan Velandia[/eluser]
+2 for prestondocks, there's no reason to put querys into the view... think ahead!

Please check this thread, It uses mvc structure. The tables names are different but it’s easy (I think) to figure it out

http://ellislab.com/forums/viewthread/149458/

hope it helps


Run query in view rather than controller - El Forum - 11-11-2010

[eluser]Sean Gates[/eluser]
+3 for prestondocks, +1 for Juan Velandia.