在视图 Yii-2 中如何从 compose() 获取参数? [英] how get parameters from compose() in view Yii-2?
本文介绍了在视图 Yii-2 中如何从 compose() 获取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在视图 Yii-2 中从 compose() 获取参数?
how get parameters from compose() in view Yii-2?
我尝试:
/controllers/SiteController
/controllers/SiteController
Yii::$app->mailer->compose('layouts/html.php', ['model' => 'trtrtrtrt',])
->setFrom('ergegergerger@gmail.com')
->setTo('ergergergegerg@mail.ru')
->setSubject('TEST')
->send();
邮件/布局/html.php
mail/layouts/html.php
<?php
use yii\helpers\Html;
use yii\mail\BaseMailer;
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message being composed */
/* @var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?>Тестовое письмо</title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div style="background-color: green;">Приветик !</div>
<?= Html::encode($model) ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
我收到错误未定义的变量:模型" - <?= Html::encode($model) ?>
i get error "Undefined variable: model" - <?= Html::encode($model) ?>
如何从 compose() 获取参数?
how get parameters from compose()?
推荐答案
您正在调用布局文件中的参数.但是参数 model
仅在视图中可用.
You are calling a parameter in the layout file. But the parameter model
is available only in the view.
所以你必须改变代码:
mail/layouts/html.php
<?php
use yii\helpers\Html;
use yii\mail\BaseMailer;
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message being composed */
/* @var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?>Тестовое письмо</title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div style="background-color: green;">Приветик !</div>
<?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
mail/emailview.php
<?= Html::encode($model) ?>
php代码
Yii::$app->mailer->compose('emailview.php', ['model' => 'trtrtrtrt',])
->setFrom('ergegergerger@gmail.com')
->setTo('ergergergegerg@mail.ru')
->setSubject('TEST')
->send();
这篇关于在视图 Yii-2 中如何从 compose() 获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文