I am able to send mail using swiftmailer extension. I am also able to include the view file from #app/mail folder.
Now I am wondering how I can include the data for my model views for example say I have a Model City.php and related view as view.php or index.php(grid-view) how can I include the data rendered in view.php(single record) or table data in index.php in mail body.
In short I want to include the default data rendered in yii2 in views or index in mail body.
Hi, I have seen this example like - Yii::$app->mailer->compose('viewName', ['variable' => $variable])
another example - Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
I have tried like this without much success:
Yii::$app->mailer->compose('medicine-request-entry/html',['medicine_request_entry'=>$form])
but I am getting the error undefined variable form. medicie_request_entry is the folder in views folder.(not in #app/views)
but couldn't get it. Say my view name in /mail/ subfolder is say report.php and I have a folder in my views subfoler /city/ and in city folder there is view.php and index.php how I can specify this in the parameter in the example code.
Any suggestion will be greatly appreciated.
Thanks.
Ok I found the solution and putting the answer for anyone having the same difficulty
I modified the code in my controller like:
Yii::$app->mailer->compose('#app/views/medicine-request-entry/view',['model'=>$model])
But I still didn't get, how to use layout given in #app/mail or to send the mail as html.
Thanks.
\Yii::$app->mailer->htmlLayout = "#app/mail/layouts/html";
$message = Yii::$app->mailer->compose('#app/mail/welcome');
var_dump($message);
Related
I have following Action in one of my controllers:
public function validateMessageAction() {
$sth = new ViewModel($this->params('params'));
$adServerOutput = $this->forward()->dispatch('Adserver/Controller/Index', array('action' => 'index'));
$sth->addChild($adServerOutput, 'adServerOutput');
return $sth;
}
Next I have a following template:
adServerOutput: <?php echo $this->adServerOutput; ?><br><br>
Validate message link clicked<br>
Of course the Adserver/Controller/Index and corresponding template exists as well, can be called and once called - shows correct output (from its template).
Unfortunatelly what I get after going to validateMessage action is only the "Validate message link clicked" text - nothing that is setup in Adserver/Controller/Index->indexAction().
Any idea why that works this way ?
Additional information to that might be that actually the validateMessageAction() is also triggered from different controller via $this->forward()->dispatch(...) - maybe that might be the case ?
EDIT: I have checked that as well - and even if the forward() call is only done once - still the problem persists...
I will really greatly appreciate any hints - sitting on this for 2 days already and have no clue even what to check further :)
EDIT: ADDITIONAL TESTS and information
I have done some additional tests and found here are some additional info:
adServer/Controller/indexAction has a layout.phtml template that specified layout (for test purposes shows string "AdServer Layout")
validateMessageAction has a layout.phtml tenplate that specified layout as well (for test purposes shows string "validateMessage Layout)
Now when I only try to call
$a = $this->forward()->dispatch(...)
even if $a is not assigned or anyhow used (only this association is performed) - the page immediatelly starts using Adserver layout (but still contents are not shown) - ignoring the layout that was specified for validateMessageAction() (of course when I remove that assotiation - the layout for validateMessageAction() is back immediatelly).
As I understood in the documentation forward should not make any action, but rather only result with string containing rendered module.
There can however be one additional information in here - is that I use EdpModuleLayouts - maybe that might be somehow source of the problem ?
(Posted on behalf of the OP).
Problem was caused by EdpModuleLayouts - removing layout for Adserver (which actually should not have a layout) solved the problem.
Mail::sendTo($to, 'OctoberCMS.PhotoElegance::mail.contactform', $params);
When this line of code is called I get back an error which says the following:
"No hint path defined for [OctoberCMS.PhotoeElgance] on line 112 of vendor\laravel\framework\src\Illuminate\View\FileViewFinder.php"
In simple, I am trying to send mail when the contact form is submitted. The code is inside a function called onStart(). I discovered that the appname is OctoberCMS. After the dot I have PhotoElegance as that is the website name.
After the hint path (OctoberCMS.PhotoElegance) I am calling the static function (mail.contactform) to my defined contact form which has been built in the CMS.
Where do I find out the appname and website name. How do I define these if I want to change them. I understand this is to do with name spacing but I cannot figure it out.
hi the way you try to send an email is called "Mail view" this is the way you do send mail form a plugin, and the path to the mail view is author.plugin::path.to.view.
From the very short definition of your problem i can tell that you are not using plugin but the dynamic pages feature of october cms so you must use "mail template" .
Go to setting > find mail->mail template in the left side bar > click new template chose a code once done you can use this tempalte to send email from dynamic page.
Mail::sendTo($to, 'template.code', $params);
I am using Yii bbii forum module and it works fine. But now I want to add comments-module so every forum post could be seperately commented.
At the begining it might look:
I followed instruction what is here, but I can't make it work :(
And why I even need to include this file, if I want to add just comment?
When I added the same widget to user page (just for testing) - I got "This item cann't be commentable" and it's fine because probably I don't have correct configuration in main.php.
Difference between widget in user model view and forum view is data passed in it.
Here:
public function actionPostComment()
{
if(isset($_POST['Comment']) && Yii::app()->request->isAjaxRequest)
{
$comment = new Comment();
$comment->attributes = $_POST['Comment'];
var_dump($comment);
var_dump returned this when tried to submit comment in forum, and here in user view page.
And probably it is not even possible to combine these to modules? I'm really new in Yii.
Updated:
Basically what I have done is:
exstracted comment module (under protected->modules)
in main.php (under protected->config) added all cofiguration in modules array:
'comments'=>array(
//you may override default config for all connecting models
'defaultModelConfig' => array(
//only registered users can post comments
'registeredOnly' => false,
'useCaptcha' => false,
.......
and in view file _post.php added following:
<?php $this->widget('comments.widgets.ECommentsListWidget', array(
'model' => $data,
));
and var_dump($data) gives this (when this is called in controller where post is reseaved).
An error message was given here:
include(BbiiPost.php): failed to open stream: No such file or directory
You said that the Bbii was working with Yii and it broke when you tried to add comments.
The links to your var_dump files are broken, but I did try to read them ;)
It looks like the comments module is interfering with the POST path so that when the form submission comes in it is in a different path from the root which is confusing the YiiBase's autoloader.
You could try explicitly adding the path to BbiiPost.php to the autoloader's search path, or finding where the include("BbiiPost.php") line is and changing it to an absolute path.
Another possibility is that the forum page you are on has links to add comments but the page routing has not been taken from the route. So it might be that the POST link to the comments is actually at /forum/123/comment/add instead of just /comment/add. So when the form is submitted it is trying to the comments/add controller/action but finding that it is in /forum/view and getting confused about the paths to the include files.
I have generally found that the instructions on the Yii (v1) [v2 docs are much better] site for these modules is flaky at best. Quite often the source download link on the page points to an old buggy version of the code as the project has usually moved somewhere else. You generally need to have a pretty good PHP/Yii knowledge to debug these user-submitted modules and get them working.
I want a piece of code on the index of my Code Igniter's script so I can change the identety or name of my controller from agent69 to agent007_and_supergirl,and also a way to beat any rule that pages might have against using underscore to separate words as an amendment.
In other words I want that all the calls that the processor of my server has inside my code igniter for agent69 be translated to calls to agent007_and_supergirl
Is just a change of identety for the controller without altering the main controler's functionality and without getting my hands dirty with coding.
If you want re route your default controller url, you have to edit routing configuration like this:
in application/config/route.php
$route['agent007_and_supergirl'] = 'agent69';
Now agent69 Controller will be accessible by http://youriste.com/agent69 and http://yoursite.com/agent007_and_supergirl as well
CodeIgniter URI Routing Guide
Working on config/routes.php yelded miserabe results on past,remember that is an identity matter
And I want all the calls of agent69 be sent to agent007_and_supergirl that is its new identity
What was successfull on the past about this mattar was controller and file cloning,it worked masterfully
but this only intercepted few server calls so for me to get all the server calls, I need to clone every
single fie on the script so I feel silly teling you again thats why I didnt want to get my hands dirty with code
because is plenty of code.
Well hope that you can help me master this code that goes on the index of my code igniter script--///The code cant appear here so its below in the comment to lighta thanks 4 readin
I have controller and there is a function which calls password. There I have email form:
$this->email->from('system#domain.us', "domain.us");
$this->email->to($user_data['email']);
$this->email->subject(lang('users_validations_passwordemail_title'));
$this->email->message(lang('users_validations_passwordemail_hi').", ". ucfirst(strtolower($userInfo[0]['username'])) .lang('users_validations_passwordemail_text'). $user_data['random_string'] ."");
$this->email->send();
and in the controller contructor function I have:
$this->lang->load('controllers', $this->session->userdata('session_lang'));
but when I tried to send message I've got this message:
Unable to load the requested language file: language/france/email_lang.php
so how tu use it? why i've got this error? how to fix it?
BTW - I tried to use lang('users_validations_passwordemail_title') simple (not in email form) and that worked for me..
Well, you are loading a file which does not exist. If you have a france language folder, you have to have email_lang.php file in it with your required data. In this case, your required language key