• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Login System

#1
[eluser]Unknown[/eluser]
Hi all, I'm starting off developing a cms, but there's a few questions i had:

1.i know from a view, you would just use set_value ( 'username' ) to output the value back out, but in the controller, do i use set_value as well?

2.how would you set an error message to show up without creating a callback that would inevitably run when you form_validation->run();? I see form validation as a 2 step validation: first validate without the db, then check against the db ( see code )

Code:
<?php
class Login extends Controller {
    function index() {
        $this->load->helper ( 'form' );
        $this->load->library ( 'form_validation' );
        
        $this->form_validation->set_rules ( 'username', 'Username', 'trim|required|xss_clean' );
        $this->form_validation->set_rules ( 'password', 'Password', 'trim|required|xss_clean|md5' );
        
        if ($this->form_validation->run () == FALSE) {
            $this->load->view ( 'loginview.php' );
        } else { //if the form is valid, then we'll check the database
            $this->load->model ( 'cms_model' );
            if ($this->cms_model->login ( set_value ( 'username' ), set_value ( 'password' ) )) {
                $this->load->view ( 'loginsuccess.php' );
            } else {
                //$this->form_validation->set_message('username','password mismatch);
                $this->load->view ( 'loginview.php' );
            }
        }
    }
}
?>

Thanks in advance,

#2
[eluser]imn.codeartist[/eluser]
In your controller set your error message in session

Code:
$this->session->set_flashdata('msg','your message');

in your view

Code:
if($this->session->flashdata('msg'))
{
       echo $this->session->flashdata('msg');
}

this will set error message in the session and once it print it flushes itself


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.