Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom routing rule not match the User Guide #1609

Closed
nyufeng opened this issue Dec 14, 2018 · 1 comment
Closed

Custom routing rule not match the User Guide #1609

nyufeng opened this issue Dec 14, 2018 · 1 comment

Comments

@nyufeng
Copy link
Contributor

nyufeng commented Dec 14, 2018

Describe the bug
https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html

$routes->add('blog/joe', 'Blogs::users/34');

A URL containing the segments “blog/joe” will be remapped to the “Blogs” class and the “users” method. The ID will be set to “34”:

But actually the method is users/34

visit page show 404

CodeIgniter 4 version
version 4.0.0-alpha.3

Affected module(s)
Routes

Expected behavior, and steps to reproduce if appropriate
In application/Config/Routes.php set:

$routes->add('blog/joe', 'Blogs::users/34');

In application/Controllers/Blogs.php set:

<?php namespace App\Controllers;

use CodeIgniter\Controller;

class Blogs extends Controller
{
    public function users($id){
        echo $id;
    }
}

visit /blog/joe and /blogs/users/34 should show
snipaste_2018-12-14_15-28-41
but visit /blog/joe show
snipaste_2018-12-14_15-28-27

@lonnieezell
Copy link
Member

There's not a bug there. When you're specifying the "to" portion of the route, users/34 it expects the last, non-placeholder segment, to be the method called. I'm guessing the 34 is supposed to be the ID of the user or post? In that case you need a placeholder to accept the ID from the URL and pass it as an argument to the method.

$routes->add('blog/joe/{id}', 'Blogs::users/$1');

Please read the user guide for more information, or ask at the forum for help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants