Reputation: 321
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<id:\d+>/<action:\w+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
Not it is clear why references of a /controller/name-action/id/1 do work, /controller/1/name-action do not work, and without hyphen everything works, according to documentation of action name-action it is actionNameAction??
public function actionNameAction($id) {
// some code
}
In advance all thanks.
Upvotes: 1
Views: 515
Reputation: 439
I think you are confused with zend framework and Yii2.In yii2 it is actionActionName.While using it in url's the capitals are changed to lower case with a hyphen preceding them. For example, if the controller is Orders and the action is OrderAnalysis then the url would be something like orders/order-analysis. Moreover any id or any other parameter is added only after routing the app to its correct controller action. Also now coming to your problem I think i found a backdoor to it-
// creates an anchored URL: /index.php?r=post%2Fview&id=100#content -------------------------- echo Url::to(['post/view', 'id' => 100, '#' => 'content']);
Upvotes: 0