-
-
Save pebriana/c4982929e156598eaf7b to your computer and use it in GitHub Desktop.
REST routing with Yii 2 UrlManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
/* ... */ | |
'components' => array( | |
/* ... */ | |
'urlManager' => array( | |
'enablePrettyUrl' => true, | |
'rules' => require(__DIR__ . '/routes.php'), | |
), | |
/* ... */ | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\web\UrlRule; | |
return array( | |
// REST routes for CRUD operations | |
'POST <controller:\w+>s' => '<controller>/create', // 'mode' => UrlRule::PARSING_ONLY will be implicit here | |
'<controller:\w+>s' => '<controller>/index', | |
'PUT <controller:\w+>/<id:\d+>' => '<controller>/update' // 'mode' => UrlRule::PARSING_ONLY will be implicit here | |
'DELETE <controller:\w+>/<id:\d+>' => '<controller>/delete', // 'mode' => UrlRule::PARSING_ONLY will be implicit here | |
'<controller:\w+>/<id:\d+>' => '<controller>/view', | |
// normal routes for CRUD operations | |
'<controller:\w+>s/create' => '<controller>/create', | |
'<controller:\w+>/<id:\d+>/<action:update|delete>' => '<controller>/<action>', | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment