class Department extends \yii\db\ActiveRecord {
/**
* @return \yii\db\ActiveQuery
*/
public function getBuildings() {
return $this->hasMany(Building::className(), ['department_id' => 'id']);
}
// ...
}
var_dump($department->buildings);
class Building extends \yii\db\ActiveRecord {
/**
* @return \yii\db\ActiveQuery
*/
public function getDepartment() {
return $this->hasOne(Department::className(), ['id' => 'department_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getRooms() {
return $this->hasMany(Room::className(), ['building_id' => 'id']);
}
// ...
}
var_dump($building->department);
var_dump($building->rooms);
class Room extends \yii\db\ActiveRecord {
/**
* @return \yii\db\ActiveQuery
*/
public function getBuilding() {
return $this->hasOne(Building::className(), ['id' => 'building_id']);
}
// ...
}
var_dump($room->building);
$car->options
function popupWindowRedirect(url, enforceRedirect)
{
if (window.opener && !window.opener.closed) {
if (enforceRedirect === undefined || enforceRedirect) {
window.opener.location = url;
}
window.opener.focus();
window.close();
} else {
window.location = url;
}
}
popupWindowRedirect(<?= Json::htmlEncode($url) ?>, <?= Json::htmlEncode($enforceRedirect) ?>);
// В контроллере
public $topicday = "defaultvalue";;
public function actionTest() {
$this->topicday = "somevalue";
// ...
}
// Вывод в представлении (layout)
<?= $this->topicday ?>
<?php $this->renderPartial('_topicday', array('topicday' => $this->topicday)); ?>
$topicday
может быть не определенно.<?= TopicDay::widget() ?>
'response' => [
'class' => 'yii\web\Response',
'format' => 'json',
'on beforeSend' => function ($event) {
$response = $event->sender;
if ($response->data !== null) {
$data = $response->data;
// Error handle
$error = '';
if( ! $response->isSuccessful) {
if(isset($data['message'])) {
$error = $data['message'];
} elseif(isset(current($data)['message'])) {
$error = current($data)['message'];
}
}
$response->data = [
'status' => $response->isSuccessful,
'code' => $response->statusCode,
'error' => $error,
];
if($response->isSuccessful) {
$response->data['data'] = $data;
}
// $response->statusCode = 200;
}
},
],
$baseUrl = str_replace('/web', '', (new \yii\web\Request)->getBaseUrl());
...
'request' => [
'baseUrl' => $baseUrl,
],
'urlManager' => [
'baseUrl' => $baseUrl,
'enablePrettyUrl' => true,
'showScriptName' => false,
],
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
// Таблица
// user
// id | name
// Модель
class User {
public function getTeam() {
return $this->hasOne(UserTeam::className(), ['id' => 'user_id']);
}
}
// Таблица
// team
// id | name
// Модель
class Team
{
public function getUsers() {
return $this->hasMany(UserTeam::className(), ['id' => 'user_id']);
}
}
// Таблица
// user_team
// id | team_id | user_id
// Модель
class UserTeam {
public function getUser() {
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
public function getTeam() {
return $this->hasOne(Team::className(), ['id' => 'team_id']);
}
}