<VirtualHost *:80>
ServerName sitename.loc
DocumentRoot "/home/username/sites/sitename/www"
ErrorLog /home/username/sites/sitename/error.log
CustomLog /home/username/sites/sitename/access.log combined
<Directory "/home/username/sites/sitename/www/">
DirectoryIndex index.php
Require all granted
</Directory>
</VirtualHost>
<?php
/**
* Created by PhpStorm.
* User: a35b62
* Date: 04.04.18
* Time: 11:58
*/
namespace frontend\controllers;
use shop\forms\ContactForm;
use shop\services\contact\ContactService;
use Yii;
use yii\rest\Controller;
class ContactController extends Controller
{
private $contactService;
public function __construct(
$id,
$module,
ContactService $contactService,
$config = [] )
{
parent::__construct($id, $module, $config);
$this->contactService = $contactService;
}
public function actionIndex()
{
$form = new ContactForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->contactService->send($form);
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
return $this->goHome();
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', 'There was an error sending your message.');
}
return $this->refresh();
}
return $this->render('index', [
'model' => $form,
]);
}
}
Всегда лучше знать правильный подход))