我正在使用CakePHP 3
并添加了一个插件cakphp-Notifier
。
我想在该插件中添加flash组件。 如何在插件中添加cakephp默认组件?
代码:
NotificationManager.php
use Cake\Controller\Component\FlashComponent;
class {
// ...
private $Flash;
public function __construct( )
{
$this->Flash = new FlashComponent();
}
// ...
public function send {
$smsAPI->sendSms($numbers, $message, $sender);
$this->Flash->success(__('SMS sent .'));
// ...
}
我收到了这个错误:
缺少必需参数$ registry 调用参数类型与声明的不兼容。
答案 0 :(得分:1)
首先,您必须在插件文件的顶部导入组件:
use Cake\Controller\Component\FlashComponent;
然后导入类
中的组件var $components = array('Flash');
然后使用您的Flash功能
$this->Flash->set(__('Error!'));
希望它有效!