FuelPHPのバージョン1.7.2で、Controller_Restを継承したクラスを使用しています。
継承したサブクラスをController_Hoge_Apiとします。
このクラスで、以下のようなソースコードを実行しました。
lang
1$json = $this->success; 2$json['data']['hoge_info'] = $hoge_info; 3$this->response($json);
以下のようなエラーが出力されました。
ERROR - 2015-05-28 08:21:40 --> Notice - Undefined property: Controller_Hoge_Api::$response in /opt/hogehoge/project/hoge-server/fuel/core/classes/controller/rest.php on line 181
該当箇所のソースを確認してみました。
lang
1protected function response($data = array(), $http_status = null) 2{ 3 // set the correct response header 4 if (method_exists('Format', 'to_'.$this->format)) 5 { 6 $this->response->set_header('Content-Type', $this->_supported_formats[$this->format]); 7 } 8 9 // no data returned? 10 if ((is_array($data) and empty($data)) or ($data == '')) 11 { 12 // override the http status with the NO CONTENT status 13 $http_status = $this->no_data_status; 14 }
ログを入れて確認してみたのですが、$this->response が存在しないと言われているようです。
しかしこのクラスのbeforeメソッドはこのようになっています。
lang
1public function before() 2{ 3 parent::before(); 4 5 // Some Methods cant have a body 6 $this->request->body = null; 7 8 // Which format should the data be returned in? 9 $this->request->lang = $this->_detect_lang(); 10 11 $this->response = \Response::forge(); 12}
つまり、$this->responseは存在するはずなのです。
エラーが出る原因は何なのでしょうか?どこかでresponseプロパティが削除されているのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。