Skip to content

URI Routing issues #278

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions