0
yii2でAPIを作成していますが、すべてのメソッドはput
メソッドのうまく機能しています。私はbefore_save
メソッドでデータを取得していますが、保存時にエラー以下になっています。Yii2残りのAPIメソッドを返す内部サーバーエラー - 不明な理由でオブジェクトを更新できません
{ "名": "内部サーバーエラー"、 "メッセージ": "不明な理由 オブジェクトの更新に失敗しました。"、 "コード":0、 "ステータス":500、
「タイプ「: "のYii \ウェブ\のServerErrorHttpException"}
ここに私のコントローラファイルである
ProductsController.php
<?php
namespace app\controllers;
use yii\rest\ActiveController;
use yii\filters\auth\HttpBearerAuth;
class ProductsController extends ActiveController {
public $modelClass = 'app\models\Product';
public function __construct($id, $module, $config = array()) {
parent::__construct($id, $module, $config);
}
public function behaviors() {
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::className(),
];
return $behaviors;
}
}
ここ
<?php
namespace app\models;
use yii\db\ActiveRecord;
use yii;
class Product extends ActiveRecord {
public static function tableName() {
return '{{%o2o_products}}';
}
public function rules() {
return [
[['name'], 'required'],
];
}
}
Product.php
モデルファイル であり、これは私のweb.php'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'showScriptName' => false,
'rules' => [
'<alias:index|about|contact|login>' => 'site/<alias>',
['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
['class' => 'yii\rest\UrlRule', 'controller' => 'products'],
['class' => 'yii\rest\UrlRule', 'controller' => 'orders'],
],
]
私が作成し、更新文にrule
を削除してみましたです。成功はない。
他に必要なことがあれば教えてください。