我可以成功使用followig代码从控制器发送电子邮件:
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name)))
;
$this->get('mailer')->send($message);
Run Code Online (Sandbox Code Playgroud)
我如何修改代码以从服务类中使用它?
我想在我的应用程序中实现Observer Pattern(不是php,这就是为什么不使用Symfony的组件).
虽然组件没有使用类来传播或监听事件,但我发现它很奇怪,因为这样可以使用继承来监听整个事件树.
我看不到使用基于名称的听众的单一优势,你能帮我解决一下吗?
HWIOAuthBundle从/ login路由触发此错误:
An exception has been thrown during the rendering of a template ("No resource owner with name 'google'.") in HWIOAuthBundle:Connect:login.html.twig at line 8.
It's even not clear why it complains about 'google' while we are not refering it anywhere, but hooking a facbook connect at the moment. Did anybody meet the same?
[1] Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("No resource owner with name 'google'.") in "HWIOAuthBundle:Connect:login.html.twig" at line 8.
at n/a
in …Run Code Online (Sandbox Code Playgroud) 我在symfony2中创建一个实体,我将实体设置为createddatetime和updateddatetime,但是当我在控制器中使用setter时,错误发生在这样
FatalErrorException: Error: Call to a member function format() on a non-object in C:\wamp\www\QuickBacklog\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\DateTimeType.php line 44
Run Code Online (Sandbox Code Playgroud)
这是我的实体代码:
/**
* Set createdDatetime
*
* @param \DateTime $createdDatetime
* @return Sections
*/
public function setCreatedDatetime($createdDatetime)
{
$this->createdDatetime = $createdDatetime;
return $this;
}
/**
* Get createdDatetime
*
* @return \DateTime
*/
public function getCreatedDatetime()
{
return $this->createdDatetime;
}
/**
* Set updatedDatetime
*
* @param \DateTime $updatedDatetime
* @return Sections
*/
public function setUpdatedDatetime($updatedDatetime)
{
$this->updatedDatetime = $updatedDatetime;
return $this;
}
/** …Run Code Online (Sandbox Code Playgroud)