私はしばらくしてそれを理解しました。
次の設定を想定
- Cakephp 2.x
- ここでのアクションは匿名ユーザーに公開されています
手順1.josegonzalezによってWebサービスプラグインをインストールします。
ステップ1.1。jsonのRouter::parseExtensionsをセットアップします
ステップ1.2。PostControllerのコンポーネントに「Webservice.Webservice」を追加します
ステップ1.3。プラグインをロードする
ステップ2.PostControllerの次のアクションを変更する必要があります
public function add() {
if ($this->request->is('post')) {
// create new Post -- this will grab the file from the request data
$newPost = $this->Post->createNew($this->request->data);
if ($newPost) {
$this->Session->setFlash(__('Your Post has been saved'));
// for normal webpage submission
if (empty($this->request->params['ext'])) {
$this->redirect('/');
} else {
// for json response to Flex client
$result = $newPost;
$error = null;
$id = null;
}
} else {
$this->Session->setFlash(__('Your Post could not be saved. Please, try again.'));
// for json response for failure to create
if (!empty($this->request->params['ext'])) {
$result = null;
$error = 'Your Post could not be saved.';
$id = null;
}
}
// this is for json response via Webservice.Webservice
$this->set(compact('result', 'error', 'id'));
}
}
ステップ3.この回答に記載されているようにFlexコードをセットアップします。これは、FlexActionscriptでJSON応答を取得する方法です。
ステップ4.3つの変数result、error、idで構成されるjson応答と、ケーキのvalidationErrorsが返されることを期待する必要があります。プラグインに記載されているように、validationErrorsをブラックリストに登録することもできます。