如何使用codeigniter中的按钮访问或转到另一个页面

时间:2016-04-11 15:12:34

标签: codeigniter

美好的一天先生/妈妈!,

请帮助我了解有关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;
}

当我点击按钮(登录)时,此网址显示

- &GT; &#34; http://localhost/myfirstwebsite/auth/login?txt_email=sample%40gmail.com&txt_password=sample123&#34;

我需要你的帮助!谢谢!

1 个答案:

答案 0 :(得分:1)

如果我理解你是正确的,你想打电话给你的方法&#34;登录&#34;当您按下登录按钮时。在您的视图中替换:

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

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

在你的confing.php中你应该设置你的base_url:

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

如果您不在config.php中使用mod_rewrite,则应设置index_page:

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

因此,当您单击登录按钮时,您的表单将指向您的基本URL以及&#34; your_controller_name / login&#34; URI段,如下所示:

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