简体   繁体   中英

How to make a pretty simple Codeigniter url route?

I've looked some websites have a simple route in their login/registration form. For instance, their form redirect to action="/function/method" . Recenttly I want to implement that route in codeigniter (I use codeigniter 3), but my form still break. I don't know how to.

Below is my simple controller:

/*
* i.e Folder: Login
* i.e Controller name: Login
* i.e steps: login/login/verify
*/

class Login extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        // Load login view
    }

    public function verify()
    {
        // Processing data from login form
    }
}

And the login form is:

<form action="<?php echo base_url('login/login/verify'); ?>" method="post" class="form-horizontal">
    <input type="text" name="username" placeholder="Username">
    <input type="password" name="password" placeholder="Password">
    <button class="btn btn-login" type="submit">Sign in</button></p>
</form>

As we can see the action is redirect to base_url()/login/login/verify or if we print this will make http://localhost/domain/login/login/verify . I think it's seem too long. What I want to is to simplify that route, for instance, action="/login/verify" . I try to make route $route['login/(:any)'] = "login/login/$1" and it's not working. A little trick maybe to rename login folder ie user , so that will be user/login/verify . But it's not what I want to.

Any idea or direction?

The issue is a you're attempting to call a method that doesn't exit.

Remember that Codeigniter's URL Scheme is: http://localhost/codeigniter_installation/controller/method/params/..../

From your question, you appear to be calling:

/login/login/verify
login - controller
login - method
verify - param 

This would be listed as: function login($action = "verify") { do_stuff() } in your controller.

When you should just be calling: /login/verify

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM