在我的 Controller 中:
namespace app\api\modules\v1\controllers;
use yii\rest\ActiveController;
use yii\filters\VerbFilter;
use yii\web\Response;
class CountryController extends ActiveController
{
public $modelClass = 'app\models\Country';
public function behaviors()
{
return [
[
'class' => 'yii\filters\ContentNegotiator',
'only' => ['index', 'view','create','update','search'],
'formats' => ['application/json' =>Response::FORMAT_JSON,],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index'=>['get'],
'view'=>['get'],
'create'=>['post'],
'update'=>['PUT'],
'delete' => ['delete'],
'deleteall'=>['post'],
'search' => ['get']
],
]
];
}
}`
我从我的POSTMAN应用程序尝试
对于创建,我使用POST http://localhost/myapp/api/v1/countries工作正常。但是对于更新,我使用PUT http://localhost/myapp/api/v1/countries/16返回16记录作为JSON输出,未按预期更新。
哪里错了?谢谢!!
最佳答案
关于rest - Yii2 Rest API PUT方法调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37025353/