ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Load single view

July 03, 2010 4:45am

Subscribe [2]
  • #1 / Jul 03, 2010 4:45am

    mxdev

    1 posts

    Hi guys,

    I’m new to CI, and right now I’m working on login system with registration. I need to load single view at a time, i.e. when the user logged in profile view should only be
    viewed but I found that profile view appended to login view. Here the code for better explanation.

    function logger(){
    
    $this->load->view('login_view.php');
    
    if ((!empty($_POST['userTextField'])) && (!empty($_POST['passwordField'])))
    {    //$_POST array not empty
        $this->load->model('login_model');
        $this->login_model->getData($_POST);
        $result = $this->login_model->checkLogin();
        
        if($result){
            echo '[removed]alert("You sucessfully logged in");[removed]';
            //create a new session.        
            $user = array('username' => $_POST['userTextField'], 'logged_in' =>'TRUE');
            $this->session->set_userdata($user);
            
            //redirect to userContent.php view page.        
            $this->load->view('userContent2.php');        
        }else    
            echo '[removed]alert("You are not registered. Please register");[removed]';    
    }else{    
        //$_POST array empty
        echo '[removed]alert("Missing data.");[removed]';    
    }
    
    }
  • #2 / Jul 05, 2010 5:56am

    ndchris

    5 posts

    CodeIgniter will handle multiple calls to the view() function, and appends the views together.
    In your code the ‘login_view.php’ is loaded at first. And if the user is logged in it appends the ‘userContent2.php’ view (in your if statement).

    You could put the $this->load->view(‘login_view.php’) in the else part. Or something similar, so that only one view gets loaded.

    Btw. if you use views don’t echo out stuff directly in your controllers. If you want to use some dynamic data in your views, use an array and pass it to the view function. Like:

    $data['login_msg'] = 'LOGGEDINblbalbalasdad';
    $this->load->view('userContent2', $data);

    And you can access this data in your view now by using $login_msg.

    You also don’t need to specify .php when you load views, just use ‘name_of_view’.
    Take a look at http://ellislab.com/codeigniter/user-guide/general/views.html

    In addition, CI provides a nice form validation class, so you don’t have to check the input like you do. http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

    The User Guide is a good place to start!

  • #3 / Jul 25, 2010 5:14pm

    mxdev

    1 posts

    how this could be, I just load the first view to get the user data and check for the input it’s not empty and then load the needed view.

    thanks

  • #4 / Jul 26, 2010 7:57pm

    ontguy

    128 posts

    As ndchris mentioned take a look the validation page in the user guide: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html.

    It shows examples the general CI approach to form validation.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases