2016-04-11 58 views
0

好日子先生/馬巖使用按鈕轉到另一個頁面!如何查看或在笨

請幫助我瞭解更多有關如何MVC的作品。我是codeigniter中的新成員,我無法真正理解控制器在使用按鈕時的工作原理。請教我如何使用按鈕..請需要您注意這裏瀏覽.. :)

我這裏有樣本代碼(登錄)

在我的HTML

<?php echo validation_errors() ?> 
    <?php echo form_open(current_url()) ?> 
    <fieldset> 
     <div class="pull-right"> 
      <label class="input login-input"> 
       <div class="input-group"> 
        <span class="input-group-addon"><i class="fa fa-user"></i></span> 
         <input placeholder = "Email Address" class = "form-control" value = "<?php echo set_value('txt_email') ?>" name = "txt_email" type="email"></input> 
       </div> 
      </label> 
      <label class="input login-input"> 
       <div class="input-group"> 
        <span class="input-group-addon"><i class="fa fa-lock"></i></span> 
         <input placeholder = "Password" class = "form-control" name = "txt_password" type="password"></input> 
       </div> 
      </label> 
      <div class = "button-inline"> 
       <button type="submit" class="login-button btn">Log in</button> 
      </div> 
      <hr class = "form group"> 

       <label> You do not have an accout yet? Please click <a>here</a> to register</label> 
      <br> 
       <h6>Note: This website is for personal user only..</h6> 
     </div> 
    </fieldset> 
    <?php echo form_close() ?> 

在我的控制器

public function login() 
{ 
    $rules = array(
     array('field' => 'txt_email', 
      'label' => 'Email', 
      'rules' => 'required|valid_email|callback_check_login|trim', 
      ), 
     array('field' => 'txt_password', 
      'label' => 'Password', 
      'rules' => 'required|trim', 
      ) 
     ); 
    $this->form_validation->set_message('callback_check_login', 'invalid Email or Password'); 
    if ($this->is_validated($rules)){ 

     $this->render_client('homepage'); 
    } 
    else{ 
    $this->render_login('login', $this->data); 
    } 
} 
public function check_login(){ 
    $where = array(
     'email' => $this->input->post('txt_email'), 
     'password' => $this->input->post('txt_password') 
     ); 
    return($this->database_model->select('tb_user', $where)) ? true : false; 
} 

,當我點擊按鈕(登錄),此URL顯示

- >「http://localhost/myfirstwebsite/auth/login?txt_email=sample%40gmail.com&txt_password=sample123

請我需要您的幫助!謝謝!

+0

笏ü想要做的好心解釋更多 –

+0

不清的信息,瞭解你的問題 –

+0

是你想登錄的用戶,並希望重定向用戶登錄後的其他頁面例如成功它將在儀表板 –

回答

1

如果我理解你正確,當你按下登錄按鈕時,你想調用你的方法「登錄」。在您的視圖替換:

<?php echo form_open(current_url()) ?> 

<?php echo form_open('your_controller_name/login') ?> 

在你confing.php你必須讓你的BASE_URL:

$config['base_url'] = 'http://localhost/myfirstwebsite'; 

如果你在你的配置不使用mod_rewrite。 php你的index_page應該設置爲:

$config['index_page'] = 'index.php'; 

所以,當你點擊登錄按鈕表單將指向你的基礎URL加上「your_controller_name /登錄」 URI片段,像這樣:

http://localhost/myfirstwebsite/index.php/your_controller_name/login