D
D
Dmitry Bay2014-12-10 18:27:26
Yii
Dmitry Bay, 2014-12-10 18:27:26

Yii url manager, a question about creating a rule?

Hello. Something shut up in this question:
There is the following rule:

'rules'=>array(
    '<view:(agreement|vendors|partners|about|howtobuy)>'=>'site/page',
     'pages/<view:\w+>'=>'/site/page',
),

There are two pages generated like :
CController::createAbsoluteUrl('/site/page', array('view'=>'test')); //получаем 'site.ru/test'
CController::createAbsoluteUrl('/site/page', array('view'=>'vendors')); //получаем 'site.ru/vendors'

If the rule
'<view:(agreement|vendors|partners|about|howtobuy)>'=>'site/page',

we get
CController::createAbsoluteUrl('/site/page', array('view'=>'test')); //получаем 'site.ru/test'
CController::createAbsoluteUrl('/site/page', array('view'=>'vendors')); //получаем 'site.ru/vendors'

If
'pages/<view:\w+>'=>'/site/page',
we get the rule on all pages site.ru/pages/page
So the question is how to make a rule so that the first occurrence would form one link, and if it does not fit the first rule, then the second one is formed?
For example:
site.ru/vendors , but site.ru/pages/nolink

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2014-12-10
@kawabanga

The slash is superfluous, this indicates the controller / action

'rules'=>array(
    '<view:(agreement|vendors|partners|about|howtobuy)>'=>'site/page',
     'pages/<view:\w+>'=>'site/page',
),

According to these rules, if something does not fit the top one, it is checked below - such priority is
CController::createAbsoluteUrl('site/page', array('view'=>'vendors')); //get 'site.ru/vendors' CController
::createAbsoluteUrl('site/page', array('view'=>'test')); //get 'site.ru/pages/test'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question