1 回答
TA贡献1810条经验 获得超4个赞
需要在 $components 数组上调用 Flash 组件,然后正常使用它,独立于调用该组件的控制器。就像是:
namespace App\Controller\Component;
use Cake\Controller\Component;
class ValidateValueComponent extends Component
{
public $components = ['Flash'];
public function validateValue($var = null){
try{
if(!$var){
throw new \Exception();
}
} catch(\Exception $e){
$action = $this->request->params['action'] === 'index' ? 'home' : $this->request->params['action'];
$controller = $action === 'home' ? 'Home' : $this->request->params['controller'];
$this->Flash->set(__('Message!'));
return $this->_registry->getController()->redirect(['controller' => $controller, 'action' => $action]);
}
}
}
- 1 回答
- 0 关注
- 117 浏览
添加回答
举报