1

I am trying implement REST api in yii by official example, and now I got lot of errors instead of response http://www.taxitaxi.kz/dispatcher/index.php/api/drivers.

Can someone clearify me what is the issue?

user2440685
  • 43
  • 1
  • 4

1 Answers1

3

Using the RESTapi for yii using the extension is pretty simple actually. However to get it working there are few things that need to be done as it properly stated in the documentation of the extension as well.

Few of the important details that you might have missed maybe :

  1. Place restfullyii into your protected/extensions directory and make sure that there is full read and write access to it. Many a times I have had extensions not working because of the server permissions.

  2. Make sure that you have changed the routes in the UrlManager properly. Possibly like this :

    'api/<controller:\w+>'=>array('<controller>/restList', 'verb'=>'GET'),
    'api/<controller:\w+>/<id:\w+>'=>array('<controller>/restView', 'verb'=>'GET'),
    'api/<controller:\w+>/<id:\w+>/<var:\w+>'=>array('<controller>/restView','verb'=>'GET'),
    array('<controller>/restUpdate', 'pattern'=>'api/<controller:\w+>/<id:\d+>', 'verb'=>'PUT'),
    array('<controller>/restDelete', 'pattern'=>'api/<controller:\w+>/<id:\d+>', 'verb'=>'DELETE'),
    array('<controller>/restCreate', 'pattern'=>'api/<controller:\w+>', 'verb'=>'POST'),
    array('<controller>/restCreate', 'pattern'=>'api/<controller:\w+>/<id:\w+>', 'verb'=>'POST'),
    
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    
  3. You have to extend the controller class where you want the api to work by changing it to ERestController. This is really important!

    Example :

       class PostController extends ERestController{ }
    
  4. Your filters and the accessRules need to be changed by appending '_' before them.

    Ex. Change the accessRules to _accessRules()

  5. And also if you go through the code of the RestController you would see that the username and password is basically taken from the parameters from the Yii::params, so you can change them in the main.php config file or you can change the authentication method to reflect yours.

Hope this solved your problem, if it did not do state where it is showing an error.

Regards,

Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
Sankalp Singha
  • 4,461
  • 5
  • 39
  • 58