带有类和方法的表单操作将添加到现有的url中


Form action with class and method adds to existing url

我有一个带有URL的登录表单-"http://localhost/ci/signin"。单击提交后,它将转到-"http://localhost/ci/login/userLogin",这会影响超链接打开问题,因为它在"登录"中搜索该页面,而"登录"实际上位于"http://localhost/ci/home".

如何解决这个问题?

我的登录表单页面代码是:

 <?php echo form_open('login/userLogin'); ?
        <div class="top-margin">
        <label>Email <span class="text-danger">*</span></label>
         <?= form_input(['name'=>'email','class'=>'form-control']); ?>
            </div>
            <div class="top-margin">
        <label>Password <span class="text-danger">*</span></label>
         <?= form_password(['name'=>'password','class'=>'form-control']); ?>    
        </div>
       <hr>
        <div class="row">
        <div class="col-lg-8">
        <b><a href="">Forgot password?</a></b>
            </div>
            <div class="col-lg-4 text-right">
            <?= form_submit(['name'=>'submit','value'=>'Sign in','class'=>'btn btn-action']); ?>
        </div>
        </div>
        </form>

我的"登录"控制器代码是:

    class Login extends MY_Controller
    {
    public function userLogin()
    {
     $this->load->library('form_validation');
     $this->form_validation->set_rules('email','Email','trim|required|valid_email');
     $this->form_validation->set_rules('password','Password','required');
     $this->form_validation->set_error_delimiters("<p class='text-danger'>","</p>");
     if($this->form_validation->run() == FALSE)
     {
        $data['title'] = ucfirst('signin'); // Capitalize the first letter
        $this->load->view('user/header', $data);
        $this->load->view('user/nav', $data);
        $this->load->view('user/signin', $data);
        $this->load->view('user/footer', $data);
     }
     else
     {
        echo "Success";
     }
 }
 }
  ?>

路线:

 $route['(:any)'] = 'user/view/$1';
 $route['default_controller'] = 'user/view';
 $route['404_override'] = '';
 $route['translate_uri_dashes'] = FALSE;

如果我正确理解您的问题和代码(从未使用过codeigniter),则可以从登录目录加载表单。

<?php echo form_open('login/userLogin'); ?

当你尝试时会发生什么:

<?php echo form_open('home/userLogin'); ?

希望这能有所帮助!:)

我自己不使用CodeIgnite,但它可能有可以正确输出URL的助手函数。

在Laravel是:

url('this/url/is/not/added/to/the/current/url');

即使您在"localhost:8000/somepage",也会输出:

"localhost:8000/this/url/is/not/added/to/the/current/url"

它是一个PHP(助手)函数,所以用PHP输出它。

是。我找到了解决问题的办法。实际上这是我的错误。Hyperlinks不工作,因为我没有为该hyperlinks编写full address。以前,我的超链接是-

<a href="home">Home</a>

现在,我把它改成…

<a href="<?= base_url();?>home">Home</a>

现在,它起作用了。享受