0

我正在尝试为 HTML 电子邮件模板设置变量,但我似乎无法访问这些变量。当我在模板中回显变量名称时,在发送的电子邮件中会显示一条错误消息“未定义的变量”。在错误描述中,它甚至显示了已设置的变量。

App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->from(array('info@example.com' => 'Test'));
$Email->to('myemail@email.com');
$Email->subject('Test email variables');
$Email->template('layout_1'); 
$Email->emailFormat('html');
$Email->viewVars(array('input_1','test input 1'));
$Email->send();

电子邮件中出现以下错误,我实际上可以看到我设置的“输入 1”变​​量。

    NOTICE (8): UNDEFINED VARIABLE: INPUT_1 [APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP, LINE 44]
CODE CONTEXT

                            <TR>
                                <TD CLASS="HEADER-BAR" VALIGN="TOP" STYLE="COLOR: #999; FONT-FAMILY: VERDANA; FONT-SIZE: 10PX; TEXT-TRANSFORM: UPPERCASE; PADDING: 0 20PX; HEIGHT: 15PX;" WIDTH="400" 
HEIGHT="15">
                                    <?PHP PRINT_R($INPUT_1); ?>
$VIEWFILE = '/APPLICATIONS/XAMPP/XAMPPFILES/HTDOCS/APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP'
$DATAFORVIEW = ARRAY(
    'CONTENT' => '',
    (INT) 0 => 'INPUT_1',
    (INT) 1 => 'TEST INPUT 1'
)
$CONTENT = ''
INCLUDE - APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP, LINE 44
VIEW::_EVALUATE() - CORE/CAKE/VIEW/VIEW.PHP, LINE 945
VIEW::_RENDER() - CORE/CAKE/VIEW/VIEW.PHP, LINE 907
VIEW::RENDER() - CORE/CAKE/VIEW/VIEW.PHP, LINE 471
CAKEEMAIL::_RENDERTEMPLATES() - CORE/CAKE/NETWORK/EMAIL/CAKEEMAIL.PHP, LINE 1582
CAKEEMAIL::_RENDER() - CORE/CAKE/NETWORK/EMAIL/CAKEEMAIL.PHP, LINE 1448
CAKEEMAIL::SEND() - CORE/CAKE/NETWORK/EMAIL/
CAKEEMAIL.PHP, LINE 1073
TEMPLATESCONTROLLER::SEND_NEWSLETTER() - APP/CONTROLLER/TEMPLATESCONTROLLER.PHP, LINE 110
TEMPLATESCONTROLLER::EDIT() - APP/CONTROLLER/TEMPLATESCONTROLLER.PHP, LINE 194
REFLECTIONMETHOD::INVOKEARGS() - [INTERNAL], LINE ??
CONTROLLER::INVOKEACTION() - CORE/CAKE/CONTROLLER/CONTROLLER.PHP, LINE 486
DISPATCHER::_INVOKE() - CORE/CAKE/ROUTING/DISPATCHER.PHP, LINE 187
DISPATCHER::DISPATCH() - CORE/CAKE/ROUTING/DISPATCHER.PHP, LINE 162
[MAIN] - APP/WEBROOT/INDEX.PHP, LINE 111

我还尝试打印显示的 $dataforview 变量,但我得到了同样的错误。

4

1 回答 1

2

我已经很久没有使用过 cake 了,但是快速查看他们的文档,他们期望将 key => value 数组传递给 viewVars() 方法。

我假设你打算这样做: $Email->viewVars(array('input_1' => 'test input 1'));

其次,您似乎将值定义为“input_1”,但尝试将其访问为“INPUT_1”。在 PHP 中,变量区分大小写。

于 2013-09-23T02:19:33.363 回答