Closed alexweb-zz closed 10 years ago
Parameter 'message' in the mail view reserved for the mail message instance. Perhaps we should change the way message instance is passed to the view to avoid collisitions.
Perhaps related #3992
I don't think we need to make change here.
It doesn't make sense that you pass in a message
parameter and you still expect message
to be the old message object.
Ok. But it's a little bit confusing, because it's not clear where $message value were missed. You passing value to variable and then it just disappears
\Yii::$app->mail->compose('message', ['message' => 'Hello world'])
->setFrom($emailFrom)
->setTo($emailTo)
->setSubject('You Have Received a New Message on ' . \Yii::$app->name)
->send();
Try var_dump($message)
object(yii\swiftmailer\Message)[135]
private '_swiftMessage' => null
public 'mailer' =>
object(yii\swiftmailer\Mailer)[133]
public 'messageClass' => string 'yii\swiftmailer\Message' (length=23)
private '_swiftMailer' => null
private '_transport' =>
array (size=0)
empty
public 'htmlLayout' => string 'layouts/html' (length=12)
public 'textLayout' => string 'layouts/text' (length=12)
public 'messageConfig' =>
array (size=0)
empty
public 'useFileTransport' => boolean false
public 'fileTransportPath' => string '@runtime/mail' (length=13)
public 'fileTransportCallback' => null
private '_view' (yii\mail\BaseMailer) =>
object(yii\web\View)[134]
public 'assetBundles' =>
array (size=0)
...
public 'title' => null
public 'metaTags' => null
public 'linkTags' => null
public 'css' => null
public 'cssFiles' => null
public 'js' => null
public 'jsFiles' => null
private '_assetManager' => null
public 'context' =>
&object(yii\swiftmailer\Mailer)[133]
public 'params' =>
array (size=0)
...
public 'renderers' => null
public 'defaultExtension' => string 'php' (length=3)
public 'theme' => null
public 'blocks' => null
public 'cacheStack' =>
array (size=0)
...
public 'dynamicPlaceholders' =>
array (size=0)
...
private '_viewFiles' (yii\base\View) =>
array (size=1)
...
private '_events' (yii\base\Component) =>
array (size=0)
...
private '_behaviors' (yii\base\Component) =>
array (size=0)
...
private '_viewPath' (yii\mail\BaseMailer) => string 'path/to/app/mail' (length=26)
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) => null
See it is object
I know. But expected to be 'Hello world' :)
Message supports magic method __toString()
, while message is empty it outputs empty string.
It's clear. But I passed string 'Hello world'. Why in view I got yii\swiftmailer\Message ? Ok, actually it's not a big problem I think.
@klimov-paul I think at this line https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMailer.php#L171
we probably should check if $params['message']
already exists. If so, we do not overwrite it.
But how we can pass message object then? Skipping it does not seems right.
Perhaps we should create special View
class for the mail, which can hold message object as its field during the rendering. This will solve #3992 as well.
I think it's a good idea.
Since the user overwrites it, it means they don't need it in the view. So why do we care if it's available ?
On Tuesday, July 1, 2014, Alexander Makarov notifications@github.com wrote:
I think it's a good idea.
— Reply to this email directly or view it on GitHub https://github.com/yiisoft/yii2/issues/4147#issuecomment-47673279.
They may need it in a view. message
is just common enough to create such conflict.
For #3992, I think we can pass $message to the layout. Unlike web layout, here $message is a known common variable, it's fine we pass it to layout.
On Tuesday, July 1, 2014, Qiang Xue qiang.xue@gmail.com wrote:
Since the user overwrites it, it means they don't need it in the view. So why do we care if it's available ?
On Tuesday, July 1, 2014, Alexander Makarov <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:
I think it's a good idea.
— Reply to this email directly or view it on GitHub https://github.com/yiisoft/yii2/issues/4147#issuecomment-47673279.
The conflict doesn't matter. If a user explicitly passes in a $message
parameter, what will he expect to get when accessing $message
? And if he wants to access the message object, he knows he should not overwrite $message
.
In the original post he has passed an email variable to setFrom but I get an error saying the email that that variable represents is not a Signature Sender on my account. How do I make sure it is?
When you try to send email for example in your MessageForm:
Then in \mail\message.php view $message variable is empty.
If you change name to something else like:
Then $msg contains data.