Create custom action in Yii2 Rest API -


i working yii2 , , want create rest api. read yii2 rest api quick start documentation, in there can use default actions(index/view/create/delete/list...). working fine

but want create action example

public function actionpurchasedcard(){      //some code } 

but couldn't it. me please, how create custome action in yii2 rest api.

config.php

'urlmanager' => [     'enableprettyurl' => true,     'enablestrictparsing' => true,     'showscriptname' => false,     'rules' => [         [             'class'=>'yii\rest\urlrule',             'controller'=>[                 'v1/resource',             ]         ],     ] ] 

document root:

htdocs/myapi/api/web/ 

i calling : http://myapi/v1/resource/purchasedcard

thanks.(sorry english not good)

you may set extrapatterns key in rule add new actions, so:

'rules' => [     [         'class'=>'yii\rest\urlrule',         'controller'=>[             'v1/resource',         ],         'extrapatterns' => [             'get purchasedcard' => 'purchasedcard',         ]     ], ] 

you may want add other properties rule such prefix or only depending on want achieve. @ full documentation know more. @ guide examples too: there example of extrapattern search action near end of guide.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -