<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>
$text = 'как политика и бизнес влияют на новости ';
$array = ['как', 'без', 'из', 'c', 'в', 'для', 'a', 'и'];
$words = explode(' ', $text);
// политика бизнес влияют на новости
echo implode(' ', array_diff($words, $array));
Yii::$app->db->createCommand('
SELECT
`users`.`name`, COUNT(`users`.`name`),
`users`.`patronymic`, COUNT(`users`.`patronymic`),
`users`.`surname`, COUNT(`users`.`surname`),
`users`.`id`, COUNT(`users`.`id`)
FROM
`users`, `users` AS `tmp`
WHERE `users`.`id` > `tmp`.`id`
GROUP BY
`users`.`name`,
`users`.`patronymic`, `users`.`surname`, `users`.`id`
HAVING
(COUNT(`users`.`name`) > 1) AND
(COUNT(`users`.`patronymic`) > 1) AND
(COUNT(`users`.`surname`) > 1)
')->execute();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
$query = Orders::find()->joinWith('items');
print_r($query->createCommand()->getRawSql());
SELECT `orders`.* FROM `orders` LEFT JOIN `order_items` ON `orders`.`id` = `order_items`.`order_id`
if (Model::loadMultiple($options->pageOption , \Yii::$app->request->post()) && Model::validateMultiple($options->pageOption)) {
foreach ($options->pageOption as $page) {
$page->save(false);
}
}
echo Html::a('Скачать', ['controller/action']);
public function actionDownload($id)
{
return Yii::$app->response->sendFile($filePath, "$file->name.$file->type", ['inline' => true]);
}
<?php
use yii\web\Request;
$baseUrl = str_replace('/backend/web', '/admin', (new Request())->getBaseUrl());
$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'your_validation_key',
'baseUrl' => $baseUrl
],
],
];
}
return $config;
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^admin(/.*)?$ backend/web/$1 [L]
# handle the case of frontend
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(.*)$ frontend/web/$1 [L]
<?php
$model = new LoginForm;
$form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'login100-form validate-form form-horizontal'],
'fieldConfig' => [
'options' => ['class' => 'form-group wrap-input100 validate-input'],
'template' => "{input}\n<span class=\"focus-input100\"></span>{label}\n{hint}\n{error}",
'labelOptions' => ['class' => 'symbol-input100'],
'inputOptions' => ['class' => 'form-control input100']
],
]);
?>
<span class="login100-form-title">
Авторизация
</span>
<?= $form->field($model, 'username')->textInput(['placeholder' => 'Логин'])->label('<i class="fa fa-envelope" aria-hidden="true"></i>') ?>
<?= $form->field($model, 'password')->textInput(['placeholder' => 'Пароль'])->label('<i class="fa fa-lock" aria-hidden="true"></i>') ?>
<div class="container-login100-form-btn">
<?= Html::submitButton('Войти', ['class' => 'login100-form-btn', 'name' => 'login-button']) ?>
</div>
<?= $form->field($model, 'rememberMe', ['template' => '<div class="text-center p-t-12"><div class="form-group field-loginform-rememberme txt1"><div class="col-lg-offset-1 col-lg-3">{input}</div></div></div>'])->checkbox() ?>
<?php
ActiveForm::end();
?>
public $depends = [
'yii\web\YiiAsset',
];
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'except' => ['error'], // или так
'rules' => [
// или так
[
'actions' => ['index', 'error'],
'allow' => true,
],
],
],
];
// Ваш статический метод в модели SizeOneHelper
public static function getSizeList(): array
{
return [
'S (55/56)',
'M (57/58)',
'L (59/60)',
'XL (61/62)',
];
}
// если в $model->size данные хранятся в виде строки, то надо привести к массиву и передать в checkboxList()
$select = explode(',', $model->size);
echo $form->field($model, 'size')->checkboxList(SizeOneHelper::getSizeList(),[
'item' => function($index, $label, $name, $checked, $value) use ($select){
if(in_array($index, $select)){
$checked = 'checked';
}
return Html::checkbox($name, $checked);
}
])
return Html::checkbox($name, $checked, ['label' => $label]);
// метод в модели SizeOneHelper
public function getSizeName()
{
return ArrayHelper::filter(self::getSizeList(), explode(',',$this->size));
}
// в DetailView получаем строку по названиям размеров
echo DetailView::widget([
'model' => $model,
'attributes' => [
[
'attribute' => 'size',
'value' => function($model){
return implode(',',$model->getSizeName());
}
]
]
]);
public function getSelectSizeList()
{
return explode(',',$this->size);
}
// метод в модели SizeOneHelper
public function getSizeName()
{
return ArrayHelper::filter(self::getSizeList(), $this->getSelectSizeList());
}
// в checkboxList
echo $form->field($model, 'size')->checkboxList(SizeOneHelper::getSizeList(),[
'item' => function($index, $label, $name, $checked, $value) use ($model){
if(in_array($index, $model->getSelectSizeList())){
$checked = 'checked';
}
return Html::checkbox($name, $checked, ['label' => $label, 'value' => $value]);
}
])
// relation
public function getUserInfo()
{
return $this->hasOne(User::class, ['id' => 'user_id']);
}
//query
$model = User::find()->with('userInfo')->one();
echo $model->userInfo->age; // example
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'defaultPageSize' => 20,
'forcePageParam' => false,
]
]);
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} (?:^|&)page=1 [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE]
public function register()
{
if($this->validate())
{
/*****/
$user->setPassword($this->password)
$user->generateAuthKey();
/****/
}
}
public function generateAuthKey()
{
return $this->auth_key = Yii::$app->security->generateRandomString();
}
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Неправильные учетные данные');
}
}
}