Не удалось установить соединение с хостом smtp.mail.ru [Сеть недоступна # 101]не благодарите за перевод)
$this->userService->create($userFrom или $userDto);
..../Service/User/Create/Service.php
всё зависит от вашей архитектуры. Выносите тогда, когда кода в сервисе становится много. Либо сразу.class UserService
{
public $users;
public $pages;
public function __construct(UserRepository $users, PageRepository $pages)
{
$this->users = $users;
$this->pages = $pages;
}
public function createUser(CreateForm $form) : void
{
if($this->users->existsByEmail($form->email)) {
thow new DomainExeption('Пользователь уже существует!')
}
$user = new User([
'username' => $form->username,
'name' => $form->name,
'email' => $form->email
]);
$page = new Page([
'name' => $form->page->name
]);
...
$transaction->begin();
try{
$this->users->save($user);
$this->pages->save($page);
$transaction->commit();
}
catch{
$transaction->rollBack();
}
//PS Транзакцию тоже можно вынести в отдельный сервис.
}
}
class UserRepository
{
public function save(User $user): bool
{
if (!$user->save(false)) {
throw new \RuntimeException('Saving error.');
}
}
public function existsByEmail(string $email): bool
{
return User::find()->andWhere(['email' => $email])->exists();
}
}
/**
* @property integer $id
* @property string $name
* @property string $slug
* @property string $title
* @property string $description
* @property integer $lft
* @property integer $rgt
* @property integer $depth
* @property Meta $meta
*
[
'attribute' => 'name',
'value' => function (Category $model) {
$indent = ($model->depth > 1 ? str_repeat(' ', $model->depth - 1) . ' ' : '');
return $indent . Html::a(Html::encode($model->name), ['view', 'id' => $model->id]);
},
'format' => 'raw',
],
"bower-asset/font-awesome": "^4.7",
"bower-asset/owl.carousel": "^2.2",
"bower-asset/magnific-popup": "^1.1",
->orderBy('id ASC');
к условию.public function getUser(){
return $this->hasMany(User:className(), ['id' => 'id_user'])
->viaTable('zakaz_tovar', ['id_tovar' => 'id'])->orderBy('id_tovar ASC');
}
public function getUser(){
return $this->hasMany(User:className(), ['id' => 'id_user'])
->viaTable('zakaz_tovar', ['id_tovar' => 'id'])->orderBy('id DESC');
}
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
'cachePath' => '@frontend/runtime/cache' //делаем общий кеш
],
'request' => [
'csrfParam' => '_csrf-myap', //тоже делаем такое же как и на frontend
'cookieValidationKey' => 'nk34HGdd8w6rf', //тоже делаем такое же как и на frontend
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_identity',
'httpOnly' => true,
'domain' => '.' . DOMAIN,
],
],
'session' => [
'cookieParams' => [
'domain' => '.' . DOMAIN,
'httpOnly' => true,
],
],
defined('DOMAIN') or define('DOMAIN', 'mysite.com');