Код: Выделить всё
public function actionPdf()
{
$session = Yii::$app->session;
$session->open();
$model = Goods::find()->all();
$client = new Requests();
$content = Yii::$app->view->renderFile('@app/views/goods/catalogue.php', ['model'=>$model]);
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.css',
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $content,
'options' => ['title' => '123'],
]);
$fileName = md5(time()) . '.pdf';
$filePath = Yii::getAlias('@app/web/upload/goods/pdf/' . $fileName);
$attachment = $pdf->output($content, $filePath, Pdf::DEST_FILE);
if($client->load(Yii::$app->request->post()) && $client->validate()){
if($client->save()){
Yii::$app->session->setFlash('success', 'Спасибо за Ваше обращение!');
Yii::$app->mailer->compose()
->setFrom([Yii::$app->params['adminEmail'] => 'Электромобили'])
->setTo($client->email)
->setSubject('123')
->attach($filePath)
->send();
return $this->refresh();
}else{
Yii::$app->session->setFlash('error', 'Ошибка! Возможно Вы не заполнили одно из полей!');
}
}
unlink($filePath);
return $this->redirect(Yii::$app->request->referrer);
}