Skip to content

TheAdnan/Yii1-API-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Yii1 REST API controller

Template for REST API controller in Yii 1

Usage

  • Add the ApiController.php file to your controllers folder
  • Change the APPLICATION_ID, and add your models in each action in the switch-case statement (remove the MyModel example before that)
  • Open the protected/config/main.php file and add this to your configuration:
'urlManager' => array(
            'urlFormat' => 'path',
            'showScriptName' => false,
            'caseSensitive' => true,
            'rules' => array(
                //API rules
                array('api/list', 'pattern'=>'api/<model>', 'verb'=>'GET'),
                array('api/view', 'pattern'=>'api/<model>/<id:\d+>', 'verb'=>'GET'),
                array('api/update', 'pattern'=>'api/<model>/<id:\d+>', 'verb'=>'PUT'),
                array('api/delete', 'pattern'=>'api/<model>/<id:\d+>', 'verb'=>'DELETE'),
                array('api/create', 'pattern'=>'api/<model>', 'verb'=>'POST'),
            ),
        ), 

Releases

No releases published

Packages

 
 
 

Languages