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

$baseUrl problem with Router #238

Closed
ridho1991 opened this issue Aug 20, 2016 · 5 comments
Closed

$baseUrl problem with Router #238

ridho1991 opened this issue Aug 20, 2016 · 5 comments

Comments

@ridho1991
Copy link
Contributor

I have function like this:
public function testpage()
{
echo 'this is a test page';
}

And added a route like this:
$routes->add('testpage', 'Home::testpage');

When I leave $baseUrl blank, then I access http://ci4.local/testpage, it show the page.
But when I set $baseUrl='http://ci4.local/', then I access http://ci4.local/testpage, it show default CI4 welcome page.
Even I try random uri like http://ci4.local/fdgfdgfdg, it also show default CI4 welcome page instead of 404 error page.

So I think this is a bug that must be solved as soon as possible.

@lonnieezell
Copy link
Member

What does your routes file look like, including the various settings in routes.php?

@ridho1991
Copy link
Contributor Author

I use default router settings, then I added this line:
$routes->add('testpage', 'Home::testpage');

@ghost
Copy link

ghost commented Aug 20, 2016

I can confirm that setting $baseUrl = ''; and leave it to automatically find the domain path works good. Setting to anything else, for example $baseUrl = 'http://ci4.local/'; only shows the default homepage on every page.

Also note on routing that absolute paths doesn't work correctly.

Example:

Code in Routes.php:

$routes->get('/profile/change-email', 'Profile::changeEmail', ['as' => 'change-email']);

Code in a view file:

<a href="<?= route_to('change-email') ?>">Change Email</a>

When clicked on link, shows:

Call to undefined method App\Controllers\Profile::change-email()

It uses the as name for controller method, although it should use the Profile::changeEmail


I currently use URLs without leading slashes, and hard-code them in views, because if I open /profile/ then click on link, it goes to /profile/profile/change-email.

Current code that works for me:

Code in Routes.php:

$routes->get('profile/change-email', 'Profile::changeEmail', ['as' => 'change-email']);

Code in a view file:

<a href="/<?= route_to('change-email') ?>">Change Email</a>

Works as indented, but I don't know which one should be fixed, the Routing or the route_to() function.

@lonnieezell
Copy link
Member

The OP's problem should now be fixed. Thanks for reporting it.

@DavisMiculis could you open a new issue for the other problem you're seeing? Too hard to keep things straight with multiple issues in the same post.

@ridho1991
Copy link
Contributor Author

You're welcome.

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