小编use*_*042的帖子

CakePHP 3 - 如何在电子邮件模板中传递对象数据

如何在电子邮件模板中传递对象数据?对象数据:

    object(App\Model\Entity\NewsletterTemplate) {

        'id' => (int) 1,
        'title' => 'Newsletter 1',
        'publish' => '21.04.2016',
        'box_title1' => 'Aenean id erat ut leo semper viverra',
        'box_text1' => 'Integer eu orci viverra',
...
    }
Run Code Online (Sandbox Code Playgroud)

电子邮件功能:

private function _send_mail($data,$user,$sender)
{
 $email = new Email('default');
 $email->template('newsletter_template','newsletter_body')
 ->emailFormat('html')
 ->subject('Newsletter')
 ->to($user)
 ->from([$sender => 'Some Name'])
 ->viewVars($data)
 ->send();
}
Run Code Online (Sandbox Code Playgroud)

我尝试了这个,但它不起作用(电子邮件模板newsletter_template.ctp):

...
                        <td class="mcnTextContent mcnTextContentLeft" style="padding-top:0; padding-left:18px; padding-bottom:9px; padding-right:18px;" valign="top">                       
                            <?php echo $title; ?>, <?php echo $publish; ?>
...
                        </td>
Run Code Online (Sandbox Code Playgroud)

email cakephp

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

CakePHP 4.1.4 - 如何在新版 CakePHP 中创建、读取和检查 cookie

在 CakePHP 3.8 中,我的控制器部分如下所示:

// ...  

public function beforeFilter(Event $event)
{
    // ...

    $this->Cookie->configKey('guestCookie', [
        'expires' => '+1 days',
        'httpOnly' => true,
        'encryption' => false
    ]);

    if(!$this->Cookie->check('guestCookie')) {
        $guestID = Text::uuid();
        $this->Cookie->write('guestCookie', $guestID);
    }
    
    $this->guestCookie = $this->Cookie->read('guestCookie');

    // ...
}


public function error()
{
    // ...
    $this->Cookie->delete('guestCookie');
    // ...
}

// ...
Run Code Online (Sandbox Code Playgroud)

在 CakePHP4 版本中如何写同样的东西?我的问题与定义 Cookie 相关。Cookie 设置在这里描述: https://book.cakephp.org/4/en/controllers/request-response.html#cookie-collections ,但不幸的是这根本没有帮助我。

我试图以这种方式解决问题:

    public function beforeFilter(EventInterface $event)
    {
//...
    
        if(!$this->cookies->has('guestCookie')) { 
            $cookie = (new Cookie('guestCookie'))->withValue(Text::uuid())->withExpiry(new \DateTime('+20 days'))->withPath('/')->withSecure(false)->withHttpOnly(true); 
            $this->cookies = new CookieCollection([$cookie]);
        } …
Run Code Online (Sandbox Code Playgroud)

cookies cakephp cakephp-4.x

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

标签 统计

cakephp ×2

cakephp-4.x ×1

cookies ×1

email ×1