Hello everyone, is there any way or even a workaround to capture the output generated by the GridView widget. I am composing an email that has a table and thought that maybe I could compose it by simply using the html created by the widget itself.
I am getting php[yii\base\InvalidConfigException] Unable to determine the request URI. upon testing. I suppose this is happening because I do not have a base view associated.
This would be the code. As you can see I am trying to get the output of the GridView widget, found it rather convenient, however I am not getting anything. Do widgets need a view in order to render the html
<?php
//contorller
public function actionNotify()
{
$clients = Clients::getPossibleCandidates();
foreach ($clients->each() as $client) {
$client->notify();
}
}
//model
public function notify ()
{
Yii::$app->mailer
->compose('alert', ['message' => $this->message])
->setFrom(['test@test.com' => 'Test'])
->setTo($this->emails)
->send();
return $this->setNotified();
}
public function getMessage()
{
return GridView::widget([
'dataProvider' => new ActiveDataProvider(['query' => $this->getUnpaidServices()]),
'tableOptions' => ['class' => 'table table-striped table-hover table-borderless'],
'columns' => [
...
]
]);
}
Okay, I was indeed able to do it without much issue, but then the problem becomes although the Gridview code is generated and e-mailed, you don’t have the CSS to style it as it normally appears.
To get it to work in the Controller, don’t forget you need to add
Sorry for late resposnse, managed that solution did not seem to adapt to my situation, the thing is that I already have my mailer setup, as in, the ‘message’ param in the compose argument is actually some part of the content of the email, more specifically the table I am trying to render. The view I am providing is actually a template slug that receives the html table through a message. Managed to find a workaround, in order to render a table in a model or controller you can do: