CakePHP routing not redirecting correctly

940 views Asked by At

I have a problem and i have no idea what's wrong.

I have build a basic authentication system, simple one. but what i noticed is that the URL- from the side bar is different from the one that is generatet from cakephp for example:

http://localhost/sitename/users

is the url that displays on toolbar.

When i do:

echo Router::url($this->here, true ); 

the result is:

http://localhost/sitename/sitename/users

The site still works, but time after time generates an error such as:

http://localhost/sitename/sitename/users/ 

Missing Controller

Error:  SitenameController could not be found.

Error:  Create the class SitenameController below in file: app\Controller\SitenameController.php
<?php class SitenameController extends AppController {

}

So i dont know what is causing the problem... If someone, anyone could help me i would very appruciate it...

Thank you very much.

1

There are 1 answers

3
rocknrollcanneverdie On

Your app is in a subdirectory so you should use

Router::url(null, true);

If the $url param is null the method will find the address to the actual controller/action. Read more here.

From the book:

$this->request->here contains the full address to the current request.

The full address includes the subdirectory as well. So if you use Router::url() with the $full param set to true it "duplicates" the subdirectory.