class DefaultController extends Controller
{
public $test;
public function actionIndex()
{
$this->test = 'test';
/* остальной код метода */
}
}
<?= Yii::$app->controller->view->context->test ?>
RewriteEngine On
RewriteRule ^(frontend|backend)/web/ - [L]
RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^admin(\/?.*)$ backend/web/$1 [L]
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(\/?.*)$ frontend/web/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
'baseUrl' => '/admin'
http://site.com
попадёте на frontend, а по адресу http://site.com/admin
- в админку.http://site.com/subsite
.RewriteEngine On
RewriteRule ^(frontend|backend)/web/ - [L]
RewriteCond %{REQUEST_URI} ^/(subsite/admin)
RewriteRule ^admin(/.*)?$ backend/web/$1 [L]
RewriteCond %{REQUEST_URI} ^/(subsite)
RewriteRule ^(.*)$ frontend/web/$1 [L]
$baseUrl = str_replace('/backend/web', '', (new yii\web\Request)->getBaseUrl());
'baseUrl' => $baseUrl . '/admin'
'default/<id:\d+>/brand-<brand:\d+>' => 'default/index',
'default/<id:\d+>' => 'default/index',
'default' => 'default/index',
echo Html::a('test', ['default/index', 'id' => $id, 'brand' => $brand])
echo Html::a('test', ['default/index', 'id' => $id])
echo Html::a('test', ['default/index'])
http://site.loc/default/index/3/brand-2
http://site.loc/default/index/3
http://site.loc/default/
SkillsChecked::loadMultiple($sk_ch, Yii::$app->request->post(), '')
Model::loadMultiple($sk_ch, Yii::$app->request->post())
SkillsChecked::validateMultiple($settings))
Model::validateMultiple($sk_ch))
['publish_at', 'datetime', 'timestampAttribute' => 'publish_at', 'format' => 'php:Y-m-d H:i'],
public function contact($email)
{
echo $this->publish_at; // 2020-06-12 14:45.
if ($this->validate()) {
echo $this->publish_at; // 1591962300
exit();
}
return false;
}
[
'template' => '{view}',
'buttons' => [
'view' => function($url, $model, $key){
return Html::a($model->title, $url)
}
]
]
[
'attribute' => 'title',
'value' => function($model){
return Html::a($model->title, ['controller/action', 'id' => $model->id])
}
]
// GirdView column
[
'attribute' => 'status',
'contentOptions' => function($model, $key, $index, $column){
return [
'class' => 'status-column',
'style' => 'cursor:pointer',
'id' => $key,
'onclick' => '
$.ajax({
url: "' . Url::toRoute('/ajax/update-status-mark') . '",
method: "POST",
data: {id: ' . $key . ', status: ' . $model->status . '},
success: function(data){
if(data == 0){
$("td#' . $key . ' span").removeClass("label-success").addClass("label label-danger").text("Blocked")
$("tr[data-key=' . $key . ']").removeAttr("style")
}
else{
$("td#' . $key . ' span").removeClass("label-danger").addClass("label label-success").text("Active")
$("tr[data-key=' . $key . ']").css("backgroundColor","rgb(226, 243, 227)")
}
}
})
'
];
},
]
// Controller action
public function actionUpdateStatusMark($id)
{
$model = $this->findModel($id);
$model->status = $model->status == 0 ? 1 : 0;
$model->save(false,['status']);
return $model->status;
}
echo ColorPicker::widget([
'name' => 'Test',
'value' => '#CCCCCC',
'options' => [
'onchange' => '
console.log($(this).val())
// ВОТ ТУТ ДЕЛАЙТЕ ЧТО ХОТИТЕ, ХОТЬ ПО AJAX ОТПРАВЛЯЙТЕ, ХОТЬ КУДА ПРИСВАИВАЙТЕ.
'
]
]);
$request = Model::find();
if(...){
$request->andWhere(...);
}
$query = $request->all(); // or one()
$query->orderBy([
'{{%table_name}}.name' => SORT_ASC,
'objectName' => SORT_ASC
]);
id - primaryKey
name - имя сотрудника
surname - фамилия сотрудника
id - primaryKey
id_employee - id сотрудника из таблицы Sotrudnik
id_position - id должности
id - primaryKey
name - название должности
public function getSotrRank()
{
return $this->hasMany(SotrRank::class, ['id_employee' => 'id');
}
public function getRank()
{
return $this->hasOne(Rank::class, ['id' => 'id_position');
}
// действие
public function actionSql($code)
{
$employee = Sotrudniki::find()->where(['code' => $code])->all();
return $this->render('sql', [
'employee' => $employee
]);
}
// вид sql
foreach($employee as $value){
echo $value->name; // имя сотрудника
// ещё один цикл для получения данных по связи SotrRank
foreach($value as $sotrRank){
// получить название должности через связь Rank
echo $sotrRank->rank->name;
}
}
'modules' => [
'support' => [
'class' => ModuleTicket::class,
// далее могут быть настройки самого модуля.
],
],
class Bootstrap implements BootstrapInterface
{
/**
* @inheritdoc
*/
public function bootstrap($app)
{
if ($app->hasModule('support') && ($module = $app->getModule('support')) instanceof ModuleTicket) {
$app->urlManager->addRules(
[
'<_m:support>/new-ticket' => '<_m>/ticket/create',
'<_m:support>/<id:\w+>' => '<_m>/ticket/view',
'<_m:support>' => '<_m>/ticket/index',
]
);
if (!$app->has($this->getModule()->queueComponent)) {
$app->set($this->getModule()->queueComponent, [
'class' => Queue::class,
'handle' => true, // whether tasks should be executed immediately
]);
}
}
// Add module I18N category.
if (!isset($app->i18n->translations['slo-nik/*'])) {
$app->i18n->translations['slo-nik/*'] = [
'class' => PhpMessageSource::class,
];
}
}
}
'siteSettings' => [
'class' => SiteSettings::class
],
'mailer' => function () {
return Yii::createObject([
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => true,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => Yii::$app->siteSettings->get('SITE.MAIL_HOST'),
'port' => Yii::$app->siteSettings->get('SITE.MAIL_PORT'),
'username' => Yii::$app->siteSettings->get('SITE.MAIL_USER'),
'password' => Yii::$app->siteSettings->get('SITE.MAIL_PASS'),
'encryption' => Yii::$app->siteSettings->get('SITE.MAIL_ENCR')
],
'messageConfig' => [
'to' => [ Yii::$app->siteSettings->get('SITE.EMAIL_ADMIN') ],
'from' => [ Yii::$app->siteSettings->get('SITE.MAIL_USER') ]
]
]);
'columns' => [
// ...
[
'class' => ActionColumn::className(),
'buttons' => [
'view' => function($url, $model, $key){
return Html::a('View', ['sotrudniki/view', 'code' => $model->id);
}
]
],
]
'SMSCenter' => function(){
return Yii::$app->createObject( [
'class' => 'integready\smsc\SMSCenter',
'login' => '',
'password' => '',
'useSSL' => false,
'options' => [
],
]);
}
'login' => Yii::$app->settings->get('password),
'components' => [
'settings' => [
// настройки компонента
]
]