class Customer extends ActiveRecord
{
public function getOrders()
{
return $this->hasMany(Order::className(), ['customer_id' => 'id']);
}
}
class Order extends ActiveRecord
{
public function getCustomer()
{
return $this->hasOne(Customer::className(), ['id' => 'customer_id']);
}
}
// SELECT * FROM `customer` WHERE `id` = 123
$customer = Customer::findOne(123);
// SELECT * FROM `order` WHERE `customer_id` = 123
// $orders - это массив объектов Order
$orders = $customer->orders;
Items::updateAll(['price' => new \yii\db\Expression('price * 1.1')]);
Items::updateAll(['price' => new \yii\db\Expression('price * 0.9')]);
$model->relUsers
это должна быть связь возвращающая массив моделей. И тогда все будет отлично:<?php foreach ($model->relUsers as $t) : ?>
<span><?= $t->username ?></span>
<?php endforeach; ?>
const STATUS_BLOCKED = 0;
const STATUS_ACTIVE = 1;
/**
* @return mixed
*/
public function getStatusName()
{
return ArrayHelper::getValue(self::getStatusesArray(), $this->status);
}
/**
* @return array
*/
public static function getStatusesArray()
{
return [
self::STATUS_ACTIVE => 'Активен',
self::STATUS_BLOCKED => 'Завершён'
];
}
$form->field($model, 'status')->dropDownList(ModelName::getStatusesArray())
'value' => Html::tag('span',
$model->getStatusName(),
['class' => 'label label-' . ArrayHelper::getValue([0 => 'danger', 1 => 'success'], $model->status)])
]
namespace frontend\components;
use frontend\components\MenuWidget;
........
echo MenuWidget::widget();
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
'frontUrlManager' => [
'class' => 'yii\web\urlManager',
'baseUrl' => 'http://site.ru',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => require(__DIR__ . '/../../frontend/config/routes.php'),
],
Yii::$app->frontUrlManager->createAbsoluteUrl('/img/media/product/images/'.$this->media_url);
'authManager' => [
'class' => 'yii\rbac\DbManager',
'cacheKey' => 'rbac',
'cache' => 'cache',
'defaultRoles' => ['guest'],
],