empty_data 允许你为你的表单类指定一个空的数据集合。如果你提交表单就会用到空的数据集合,但是没有在你的表单中调用 setData() 或者当你建立表单的时候传入数据。举例来说: public function indexAction(){ $blog = ...; // $blog is passed in as the data, so the empty_data // option is not needed $form = $this->
在方法调用前后做一些事情如果您想在调用一个方法之前后之后做一些事情,您可以在方法开始或结尾分别调度一个事件:class Foo{ // ... public function send($foo, $bar) { // do something before the method $event = new FilterBeforeSendEvent($foo, $bar); $this->dispatcher->dispatch('foo.pre_send', $event);
允许多个类向另一个类添加方法,您可以在您想要扩展的类中定义神奇的 __call() 方法,像这样:class Foo{ // ... public function __call($method, $arguments) { // create an event named 'foo.method_is_not_found' $event = new HandleUndefinedMethodEvent($this, $method, $arguments); $this->dispatcher->
发送电子邮件对于任何 web 应用程序来说,都是一个经典任务,并且具有特殊的复杂性和潜在的缺陷。不是重新创建轮,发送电子邮件的解决方案之一就是使用 SwiftmailerBundle,利用 Swift Mailer 库的能力。这个 bundle 来自于 Symfony 标准版本。配置使用 Swift Mailer 的话,您需要对您的邮件服务器配置。