Welcome Guest, Not a member yet? Register   Sign In
Load new Controller from within Controller / View?
#1

[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')?
#2

[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.
#3

[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].
#4

[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
class User_lib {

    function User_lib(){
       //Initialize variables here if you have to    
   }

   function display_login_form(){
        
        if($this->session->userdata('logged_in') == TRUE){
           $form = anchor('user/logout'); // display logout link
        }else{
           $form = form_open('user/login');
           $form .= form_label('Username','username') . form_input('username',set_value('user'));
           $form .= form_label('Password', 'password') . form_password('password');
           $form .= form_close();
        }

       return $form;
   }
}

//In any controller or view
$this->load->library('User_lib');
echo $this->User_lib->display_login_form();

This assumes you have loaded the session class and form helper somewhere.
#5

[eluser]Unknown[/eluser]
Thanks guys. I was leaning towards libraries as pickupman suggested. All of this information has been very enlightening.




Theme © iAndrew 2016 - Forum software by © MyBB