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

URI Routing issues #278

Closed
ghost opened this issue Sep 26, 2016 · 3 comments
Closed

URI Routing issues #278

ghost opened this issue Sep 26, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Sep 26, 2016

Issue

The behaviour of URI routing route_to() function doesn't match (bug?) what is said in documentation.

Relative / absolute ?

First, it says "Generate the relative URL to link[..]", but documentation example code shows it returns an absolute path, e.g. "Generates: **/users/**15/gallery/12[...]". I'm talking just about the leading slash.

Should it return with leading slash, as documentation says or should it return without leading slash, as it is currently happening?

I feel like it should return always with leading slash, because when navigating, you can go recursively and end up at e.g./users/users/users/1/ and so on.

Reverse routing

Second, the reverse URL finding works for me if I only feed the route's as parameter to the route_to() function.

Example code

Here's my example code:

Route Config (application/Config/Routes.php)

$routes->get('translations/listing/(:num)', 'Translations::listing/$1', ['as' => 'translations-listing']);

Example 1 (feeding route 'as' parameter)

In view file I write:

<a href="<?= route_to('translations-listing', $listing['id']) ?>">Listing</a>

It generates URL without leading slash:

<a href="translations/listing/27">Listing</a>

Example 2 (feeding route method)

In view file I write:

<a href="<?= route_to('Translations::listing', $listing['id']) ?>">Listing</a>

It generates error:

InvalidArgumentException
Unable to locate a valid route.

EDIT: Example 2 that works

Write in view file

<a href="<?= route_to('\App\Controllers\Translations::listing', $listing['id']) ?>">Listing</a>

Generates URL without leading slash

<a href="translations/listing/27">Listing</a>

I can post full error log if its necessary.

I didn't find any similar issues or pull requests, tested it on latest develop branch as of current, with PHP version 7.0.10, under OS X El Capitan and macOS Sierra.

@lonnieezell
Copy link
Member

  1. Yes, route_to() should return a leading slash. I think I was thinking (probably incorrect) at the time that since there's not schema or domain, that was still a relative path, just one that specified it started at the site root, whereas a full uri would include http://example.com.

  2. I'll have to dig into that more here in a day or two. I've got a sick girl so I'm making up hours for the day job at night today and tomorrow.

But - sure - a full error log wouldn't hurt.

lonnieezell added a commit that referenced this issue Oct 4, 2016
@lonnieezell
Copy link
Member

Looking closer at your second examples - that's not an error. You should have to specify the full class name of the controller, it's the only way to ensure you're targeting the appropriate class.

With the change I just pushed, it should give a trailing slash on that now. I'll look at the docs and try to clarify.

@ghost
Copy link
Author

ghost commented Oct 4, 2016

Okay, thanks for clarification on full class names!

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

1 participant