Yii 1.1: verburlmanager

simple extension to handle http methods in rules - useful for rest applications
4 followers

Use http methods/verbs in your application rules

Note: Starting from Yii 1.1.7 this functionality is included in the core framework and should be considered obsolete.

Requirements

Yii 1.1 or above

Usage

Im assuming its not the first time you are using yii's UrlManager

To set up, download the file attached, put it in your components folder or any other folder imported in your initial configuration and then in your configuration options (configs/main.php probably) add the following line

'urlManager'=>array(
         'class'=>'VerbUrlManager',//this line
         //or 'class'=>'application.extensions.verburlmanager.VerbUrlManager'

and then setup your routes

'rules'=>array(
//rules applied to all kind of requests if a specific verbs/method rule does not match/trigger first
        '<_c:\w*>/<_a:\w+>/<id:\d+>'=>'<_c>/<_a>',
        //rules for post requests
        '@post'=>array(
                '<_c:\w+>'=>'<_c>/create',
                '<_c:\w+>/<id:\d+>'=>'<_c>/update',
        ),
        //rules for put requests
        '@put'=>array(
                '<_c:\w+>'=>'<_c>/create',
                '<_c:\w+>/<id:\d+>'=>'<_c>/update',
        ),
        '@get'=>array(
                '<_c:\w+>/<id:\d+>'=>'<_c>/details',
                '<_c:\w+>/<q:\w+>'=>'<_c>/search',
                '<_c:\w+>'=>'<_c>/list',
        ),
        //case insensitive
        '@DELETE'=>array(
                '<_c:\w+>'=>'error/400',
                '<_c:\w+>/<id:\d+>'=>'<_c>/delete',
        ),
        //rule is a string, which means that all requests go to a fixed route 
        '@HEAD'=>'error/501'
)

suport/forum link

Version

version 0.2 = fixed bug that was causing string/fixed routes not to work properly

version 0.1 = little bug fixed that was causing it to doesnt trigger the routes sometimes

--

If you like it please vote

Be the first person to leave a comment

Please to leave your comment.

Create extension