0

変数名でメールを送信したい。次のようにアクションを作成しました。

$product = $this->getDoctrine()
            ->getRepository('EnsNewBundle:Products')
            ->find(2);



        $message = \Swift_Message::newInstance()
        ->setSubject('Hello Email')
        ->setFrom('ucerturohit@gmail.com')
        ->setTo('ucerturohit@gmail.com')
        ->setContentType("text/html")
        ->setBody($this->renderView('EnsNewBundle:Default:index.html.twig'));
    $this->get('mailer')->send($message);

    return $this->render('EnsNewBundle:Default:index.html.twig',array('name'=>$product->getName()));

$product->getName()ここではメールでデータを送信したいと思います。index.html.twig私は次のように定義しました:

Id of the product 5<br/>
Name of the product {{name}} <br/>
Description Fast Internet browsing speed

このアクションを実行すると、エラーが発生しますundefined variable name in index.html.twig。メールを送信する前にこの値を設定したい場合はどうすればよいですか。メール本文のハードコードを作成しても問題ありません。

4

2 に答える 2

0

Doctrine のメソッドfind()は、単一のオブジェクトではなく、結果のコレクションを返す必要があります。

おそらく使用する必要がありますfindOneByXXX()

于 2012-08-07T11:16:27.693 に答える
0

このことだけを追加しましたが、問題は解決しました。

 ->setBody($this->renderView('EnsNewBundle:Default:index.html.twig',array('name1'=>$product->getName())));
于 2012-08-07T11:21:29.920 に答える