小编Uda*_*dan的帖子

如何从Symfony2服务类发送电子邮件?

我可以成功使用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)

我如何修改代码以从服务类中使用它?

php email symfony

9
推荐指数
1
解决办法
6408
查看次数

为什么Symfony EventDispatcher对事件使用任意名称而不是基于类的传播?

我想在我的应用程序中实现Observer Pattern(不是php,这就是为什么不使用Symfony的组件).

虽然组件没有使用类来传播或监听事件,但我发现它很奇怪,因为这样可以使用继承来监听整个事件树.

我看不到使用基于名称的听众的单一优势,你能帮我解决一下吗?

design-patterns event-dispatching symfony observer-pattern

7
推荐指数
1
解决办法
686
查看次数

奇怪的HWIOAuthBundle和twig错误"没有资源所有者的名字'谷歌'."

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)

connect symfony twig hwioauthbundle

2
推荐指数
1
解决办法
1634
查看次数

如何在symfony2中删除日期时间错误?

我在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)

php doctrine symfony doctrine-orm

0
推荐指数
1
解决办法
2305
查看次数