我在cakephp3中创建了一个名为WdContactForm的插件。 在插件控制器的功能内,我需要发送一封电子邮件 但是给我这个错误:
Could not send email: Declaration of WdContactForm\Controller\AppController::beforeFilter() should be compatible with App\Controller\AppController::beforeFilter()
我已经阅读过关于添加的内容:
use Cake\Event\Event;
我已经做到了。 但我无法解决问题
这是我的插件内的控制器:
namespace WdContactForm\Controller;
use Cake\Event\Event;
use WdContactForm\Controller\AppController;
use Cake\Core\App;
use Cake\Utility\Security;
use Cake\Utility\Inflector;
use Cake\ORM\TableRegistry;
use Cake\Core\Configure;
use Cake\Mailer\Email;
class ContactFormsController extends AppController
{
public function initialize()
{
$this->loadComponent('Flash');
$this->loadComponent('Admin');
}
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
//other functions
//...
}
public function send_email()
{
$email = new Email('default');
$email->from(['test@test.it' => 'My Site'])
->to('test@test.it')
->subject('About')
->send('My message');
}
}
这是我在插件中的AppController:
namespace WdContactForm\Controller;
use Cake\Event\Event;
use App\Controller\AppController as BaseController;
class AppController extends BaseController
{
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
}
}
我该如何解决?