CakePHP Controller Alias

I know that there are several other topics on this subject, but not them seem to fit my needs.

What i have

  • example.com/log/
  • LogsController.php

I have LogsControllerinstead of LogController(plural) because CakePHP wants you to have plural controllers.

But, as you might know / notice, it example.com/log/will never use LogsControllerbecause of the missing 's' in the url.

Now I want to be /log/*redirected to /logs/*. Works fine with the following code:

Router::connect ('/log/*', array('controller'=>'logs'));

But, when I try to access example.com/log/actions/foo/bar, it does not work. So after some Googeling, I found this:

Router::connect ('/log/:action/*', array('controller'=>'logs'));

It works great. But now when I try again to access example.com/log/, it says

: LogController .

: URL-, /log/ LogsController , LogController.

, , flight => FlightsController, profile => ProfilesController.


. , . - .

+5
4

, IRC . .

Router::connect('/flight/:action/*', array('controller'=>'flights'));
Router::connect('/flight/*', array('controller'=>'flights'));

. , , :

Router::connect('/flight/*', array('controller'=>'flights'));
Router::connect('/flight/:action/*', array('controller'=>'flights'));

.

, 2 . , , . FormsHelper . , , script. .

+10

.

Router::connect('/flight', array('controller'=>'flights','action'=>'index'));
Router::connect('/flight/:action/*', array('controller'=>'flights'));

, URL-, , , .

+1

. , , , Inflector (/lib/Cake/Utility/Inflector).

log uninflected. , 's'. LogController log .....

app/config/bootstrap.php

Inflector::rules(
    'plural',
    array(
         'uninflected' => array('log')
    )
);

log uninflected Core, .

0

, :

class LogsController extends AppController
{
public $name = 'Log';
..... YOUR REMAINING CODE ......
}

The connector of your router will remain the same. Please ask if this works for you.

-1
source

All Articles