Neil Bryson Neil Bryson - 1 year ago 278
PHP Question

Yii2 pass parameters to mail layout

Is there any way to access your parameters within a mail layout when using the

Yii mailer
class? I can access
from the view but not the layout.


$params = array(
"model" => $model

$message = Yii::$app->mailer->compose([
'html' => $view.'Html',
'text' => $view,
], $params)

I know that for a standard web view you would set
to access variables in the layout but this doesn't appear to work for the mailer.

Any ideas?

Answer Source

I'd do something similar to how you get breadcrumbs back to the view.

//In your view file, model was passed down via compose as you have it.
//this adds model element to the View object's params.
$this->params['model'] = $model; 

//In your layout
echo $this->params['model']->attribute;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download