trejder
trejder

Reputation: 17505

Change UrlManager for just one controller

My Yii 1.x application has UrlManager configured to generate / use URLs like content/show.html:

'urlManager'=>array
(
    'class'=>'UrlManager',
    'showScriptName'=>false,
    'urlFormat'=>'path',
    'urlSuffix'=>'.html',
    'rules'=>array
    (
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:[\w\-]+>/<action:[\w\-]+>'=>'<controller>/<action>'
    )
),

I have also overridden CUrlManager -> UrlManager to implement Qiang's solution, that allows me to use hyphenation of routes, that is an-action-name that points to standard anActionName.

I'd like to keep it that way, but I'd like to extend it, so for one controller (used for AJAX calls) it does not uses urlSuffix and generates / uses URLs in this format: ajax/get-published-files.

Since I'm a complete newbie (nearly ignorant) in regular expressions, I haven't conducted much of my own researches, before asking, because I don't even know, where to and what for actually search.

Upvotes: 0

Views: 93

Answers (1)

DarkMukke
DarkMukke

Reputation: 2489

You can always make your suffix part of your pattern instead of your global configuration

for example :

    'ajax/<action:\w+>'=>'ajax/<action>',
    '<controller:\w+>/<id:\d+>.html'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>.html'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>/<id:\d+>.html'=>'<controller>/<action>',
    '<controller:[\w\-]+>/<action:[\w\-]+>.html'=>'<controller>/<action>',

and ofc drop the suffix part of your urlManager config

Upvotes: 1

Related Questions