SDKiller / zyx-phpmailer

PHPMailer integration for Yii2 framework
BSD 3-Clause "New" or "Revised" License
2 stars 5 forks source link

How can I pass params to the view ? #7

Closed adantart closed 8 years ago

adantart commented 8 years ago

I tried like this: https://github.com/yiisoft/yii2/issues/3590 but it's not working.

Even I tried to access from the view to $this->context->view->params but it's not working.

How can I pass params to the layout ? Thank you !

SDKiller commented 8 years ago

Hi.

Currently \yii\mail\BaseMailer::render() does not support passing additional params to layout (as far as I remember, there was a discussion on the issue).

You may try a workaround like this - I just tried and it worked for me:

        $layoutParams = [
            // some data to be rendered in layout
            ...
        ];

        $viewParams = [
            // some data to be rendered in view
            ...
        ];

        $mailer = Yii::$app->getMailer();
        $mailer->getView()->params = $layoutParams;

        $mailer->compose('viewName', $viewParams)
            ->setFrom(['admin@example.com' => 'Admin of Example.com'])
            ->setTo(['user@example.com' => 'Example user'])
            ->setSubject('Example email')
            ->send();
adantart commented 8 years ago

Working ! Thanx a lot !

SDKiller commented 8 years ago

You're welcome