特定のフォーム専用のバリデーションと、その後の処理をまとめたクラス(Formクラスを継承した)を用意します。
Controllerでデータ操作前にそのクラスを呼びエラー時にFlashをわけて出したいのですが、
Controller
$validation = new CustomValidationForm(); if(validation->execute($data)){ // バリデーションエラー処理 $this->Flash->error(__('Error')); }
とした場合は正常に動作するのですが、
バリデーションクラスのexecuteメソッド内で
$this->Flash->error(__('Another Error'))
とした時に
Call to a member function error() on null
となってしまいます。
念のためバリデーションクラス側で
use Cake\Controller\Component\FlashComponent;
としていますが、
これでは駄目なのでしょうか?
または
public function initialize() { $this->loadComponent('Flash'); }
これでも同じエラーとなります。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。