trong bộ điều khiển của tôiYii2 Rest API PUT phương pháp không hoạt động
` không gian tên ứng dụng \ 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']
],
]
];
}
}`
tôi cố gắng từ Postman tôi App
Đối tạo tôi sử dụng POST http://localhost/myapp/api/v1/countries trình fine.But Bản cập nhật tôi sử dụng PUT http://localhost/myapp/api/v1/countries/16 nó sẽ trả về 16 kỷ lục như JSON đầu ra không được cập nhật như mong đợi.
Điều gì đã xảy ra? Cảm ơn!!
Nếu cuộc gọi PUT trả về đúng đối tượng có vẻ như UpdateAction đang hoạt động tốt. Bạn có chắc chắn các giá trị bạn đang đăng nằm trong tập 'rules()' của bạn không? – jagsler