E
E
EVOSandru62016-05-16 20:12:34
Yii
EVOSandru6, 2016-05-16 20:12:34

How to make CNC on a category/product in Yii1 and merge a slash between them?

Good afternoon,
Now I have a method for the link in the Products class:

public function getUrl() {
        return Yii::app()->createUrl('/products/view', [
            'id'        =>   $this->id,
            'category'  =>   $this->category->name_alias,
            'alias'     =>   $this->name_alias,
        ]);
    }

public function relations() {
    return  [
                       'category'              =>      [self::BELONGS_TO,  'CategoryProducts', 'category_id'],
    ];
  }

1. The following url is formed : domen/products/127/caterory-alias-name/alias-name
2. Desired url : domen/products/caterory-alias-name/alias-name
urlManager :
'/'                                                         =>  'site/index',
        '<action:(login|logout|registration)>'                      =>  'users/<action>',
        '<action:(contact)>'                                        =>  'site/<action>',
        'products/<id:\d+>/<category:[\w_-]+>/<alias:[\w_-]+>' => 'products/view',
        '<controller:\w+>/<id:\d+>'                                 =>  '<controller>/view',
        'products/<id:\d+>/<alias:[\w_-]+>' => 'products/item',
        '<controller:\w+>/<action:\w+>/<id:\d+>'                    =>  '<controller>/<action>',
        '<controller:\w+>/<action:\w+>'                             =>  '<controller>/<action>',
        /** Менеджер */
        '<module:smanager>'                                          =>   '<module>/orders/index',
        '<module:smanager>/<controller:\w+>/<id:\d+>'                =>   '<module>/<controller>/view',
        '<module:smanager>/<controller:\w+>'                         =>   '<module>/<controller>/index',
        '<module:smanager>/<controller:\w+>/<action:\w+>/<id:\d+>'   =>   '<module>/<controller>/<action>',
        '<module:smanager>/<controller:\w+>/<action:\w+>'            =>   '<module>/<controller>/<action>',

But at the address:
domen/products/127/caterory-alias-name/alias-name I catch an error:
Error 404
The system could not find the requested action "127".

Although I went to products/view
How to discard the number 127, get and parse the Desired url ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Natarov, 2016-05-17
@HanDroid

Tyk
You have exactly the same principle. just repeat like that. and then change to your naming.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question