在我的控制器中:
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,它返回ID为16的记录作为JSON输出,而不是按预期更新。
出了什么问题呢?谢谢!