In Yii1 to do CNC on category/product and drain the slash between them?

Good day,

Now I'm in class Products is the method for reference:

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. Formed this url : domain/products/127/caterory-alias-name/alias-name
2. Desired url : domain/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>',
 /** The Manager */
 '<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>',</action></controller></module></action:\w+></controller:\w+></module:smanager></action></controller></module></id:\d+></action:\w+></controller:\w+></module:smanager></controller></module></controller:\w+></module:smanager></controller></module></id:\d+></controller:\w+></module:smanager></module></module:smanager></action></controller></action:\w+></controller:\w+></action></controller></id:\d+></action:\w+></controller:\w+></alias:[\w_-]+></id:\d+></controller></id:\d+></controller:\w+></alias:[\w_-]+></category:[\w_-]+></id:\d+></action></action:(contact)></action></action:(login|logout|registration)>


But at:

domen/products/127/caterory-alias-name/alias-name I catch the error:

Error 404
The system was unable to find the requested action "127".


Although I went to products/view

How can we figure 127, to receive and parse the Desired url?
July 9th 19 at 13:36
1 answer
July 9th 19 at 13:38
Tyk

You have exactly the same principle. just repeat whatever. and then change your naming.
In Your example:

'products/<alias:[\w_-]+>' => 'products/view',</alias:[\w_-]+>

The URL domain/products/AliasName

Catching unknown action AliasName

The idea is I have this:

'products/' => 'products/view',

But while the category name is not included.

In this example, the URL domain/products/CategoryAliasName/AliasName:

Catching unknown action CategoryAliasName

Tried still so:

'products/view/<category:[\w_-]+>/<alias:[\w_-]+> => 'products/view',</alias:[\w_-]+></category:[\w_-]+>


Catch:

Error 400
Incorrect query. - dudley_Ri commented on July 9th 19 at 13:41
: The idea I have this:

'products/<category:[\w_-]+>/<alias:[\w_-]+>' => 'products/view',</alias:[\w_-]+></category:[\w_-]+>
* - dudley_Ri commented on July 9th 19 at 13:44
Is it to hide the action in the url

The maximum that got to do:

URL MANAGER:

'products/item/<category:[\w_-]+>/<alias:[\w_-]+>' => 'products/item',</alias:[\w_-]+></category:[\w_-]+>


CONTROLLER:

public function actionItem($category ,$alias){

If you take away item:

'products/<category:[\w_-]+>/<alias:[\w_-]+>'</alias:[\w_-]+></category:[\w_-]+>

The request is not processed(

How to be? - dudley_Ri commented on July 9th 19 at 13:47

Find more questions by tags Yii