2016-08-19 74 views
1

誰能告訴我如何重寫actioncreate和actionupdate方法yii2 REST API ..Yii2覆蓋REST API actioncreate方法

class CabController extends ActiveController 
    { 
    public $modelClass = 'api\modules\v1\models\Cab'; 

     public function actions(){ 

     $actions = parent::actions();   

     unset($actions['create']); 
     unset($actions['update']); 

     return $actions; 
    } 

    public function actionCreate(){ 

     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; 

     $model = $this->modelClass; 
     $model->load(Yii::$app->request->post()); 
     $cur_time = date('Y-m-d H:i:s'); 
     $model->date_created = $cur_time; 
     $$model->save(false); 
    } 

如果我喜歡這意味着我有錯誤,如500內部服務器錯誤和錯誤消息像調用一個非對象的成員函數load()..如何解決這個問題.. 謝謝...

回答