![]() |
Load new Controller from within Controller / View? - 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: Load new Controller from within Controller / View? (/showthread.php?tid=31276) |
Load new Controller from within Controller / View? - El Forum - 06-12-2010 [eluser]Unknown[/eluser] I'm using a template to display the header, body, and footer. These are all views. Within the header there is the User_info view for displaying the Sign In / Sign Up or if logged in already the customary logout / control panel display. At present within the User_info PHP view i have IF statements and checks for cookie. TO me the User_info display should be a controller which then decides what view to show. From within my home page controller or template view is it possible (and proper) to load the User_info controller class? Would i use $this->load->library('controllers/User_info')? Load new Controller from within Controller / View? - El Forum - 06-12-2010 [eluser]skunkbad[/eluser] [quote author="quantis" date="1276395801"]I'm using a template to display the header, body, and footer. These are all views. Within the header there is the User_info view for displaying the Sign In / Sign Up or if logged in already the customary logout / control panel display. At present within the User_info PHP view i have IF statements and checks for cookie. TO me the User_info display should be a controller which then decides what view to show. From within my home page controller or template view is it possible (and proper) to load the User_info controller class? Would i use $this->load->library('controllers/User_info')?[/quote] Since the logged in/not logged in status is something that you would generally want to see on every page, the best thing to do is extend the controller class by making a MY_Controller. Load new Controller from within Controller / View? - El Forum - 06-12-2010 [eluser]jedd[/eluser] Hi quantis and welcome to the CI forums. Have a read of [url="http://ellislab.com/forums/viewreply/559962/"]this message[/url] and perhaps go back and read that entire thread for some context. Is this the kind of thing you're wanting to do? You might want to read up on [url="/wiki/MY_Controller"]extending the core controller[/url] in the wiki, and also in the [url="/user_guide/general/core_classes.html"]user guide[/url]. Load new Controller from within Controller / View? - El Forum - 06-12-2010 [eluser]pickupman[/eluser] Most authentication controllers will use a library for this kind of thing. You then can load the library from any controller/view for any controller. Code: // application/libraries/User_lib.php This assumes you have loaded the session class and form helper somewhere. Load new Controller from within Controller / View? - El Forum - 06-13-2010 [eluser]Unknown[/eluser] Thanks guys. I was leaning towards libraries as pickupman suggested. All of this information has been very enlightening. |