echo Select2::widget([
'name' => 'my-select2',
'data' => [1 => 'One', 2 => 'Two'],
'options' => [
'placeholder' => 'Select a number ...',
'options' => [
2 => ['disabled' => true],
]
],
]);
<select>
<option value="1">One</option>
<option value="2" disabled="disabled">Two</option>
</select>
[
'label' => 'Роль',
'value' => function($model){
return $model->authAssignment->authItem->description;
}
]
$query = User::find()->with([
'authAssignment' => function($q){
return $q->with('authItem');
}
]);
yii\widgets\ActiveField
, а точнее методы в нём:public $template = "{label}\n{icon}\n{input}\n{hint}\n{error}";
public function render($content = null)
{
if ($content === null) {
if (!isset($this->parts['{input}'])) {
$this->textInput();
}
// добавить это
if (!isset($this->parts['{icon}'])) {
$this->icon();
}
if (!isset($this->parts['{label}'])) {
$this->label();
}
if (!isset($this->parts['{error}'])) {
$this->error();
}
if (!isset($this->parts['{hint}'])) {
$this->hint(null);
}
$content = strtr($this->template, $this->parts);
} elseif (!is_string($content)) {
$content = call_user_func($content, $this);
}
return $this->begin() . "\n" . $content . "\n" . $this->end();
}
public function icon($content, $options = [])
{
$this->parts['{icon}'] = Html::tag('i', null, ['class' => 'icon-'.$this->attribute];
return $this;
}
$form = ActiveForm::begin([
'fieldClass' => 'my\widgets\ActiveField'
]);
public function getSubnet(){
return $this->hasOne(Subnet::class, ['id' => 'subnet']);
}
public function getBras(){
return $this->hasOne(Bras::class, ['id' => 'bras'])->via('subnet');
// или
// return $this->hasOne(Bras::class, ['id' => 'bras'])->viaTable(Subnet::tableName(), ['id' => 'subnet']);
}
ClientSearch {
public $brasName; // добавляем атрибут в модель поиска
}
'id',
[
'attribute' => 'brasName', // выводим в гриде
'value' => function(Client $model){
return $model->bras ? $model->bras->name : null;
}
],
$bodySafe = htmlspecialchars($this->body, ENT_QUOTES, "UTF-8");
$db->createCommand('INSERT INTO comments (nick, body)' .
' VALUES (\'' . $nickSafe . '\', REPLACE("' . $bodySafe . '", "\n", "<br />"));')->execute();
return true;
}
return false;
}
$comment = new Comment([
'nick' => Yii::$app->user->identity->email,
'body' => $this->body,
'model' => 'news',
'model_id' => 1234
]);
return $comment->save();
$result = $db->createCommand('INSERT INTO comments (nick, body, model, model_id) VALUES (:nick, :body, :model, :model_id)', [
'nick' => Yii::$app->user->identity->email,
'body' => $this->body,
'model' => 'news',
'model_id' => 1234
])->execute();
return $result;
[['date_notification'], 'date', 'format' => 'php:Y-m-d\TH:m'],
'php:Y-m-d\TH:i'
),[['date_notification'], 'required'],
[['date_notification'], 'default', 'value' => date('Y-m-dTH:i')],
date_notification
и стоит NOT NULL.$rows = Products::find()
->select(['category_id' => 'CAT.id', 'product_id' => 'PROD.id', 'product_price' => 'PROD.price'])
->from(['PROD' => Products::tableName()])
->innerJoin(['CAT' => Categories::tableName()], 'CAT.id = PROD.category_id')
->orderBy(['PROD.price' => SORT_ASC])
->asArray()->all();
$rows = ArrayHelper::index($rows, 'product_id', 'category_id');
[
1 => [
177 => ['category_id' => 1, 'product_id' => 177, 'price' => 1000],
178 => ['category_id' => 1, 'product_id' => 177, 'price' => 2000],
],
2 => [
179 => ['category_id' => 2, 'product_id' => 179, 'price' => 3000],
192 => ['category_id' => 2, 'product_id' => 192, 'price' => 4000],
],
]
self::deleteAll(['and',['id'=> $list,'collection_id'=>$collection_id]]);
and
- это лишнее. Можно просто:self::deleteAll(['id' => $list, 'collection_id' => $collection_id]);
self::find()->where(['id' => $list, 'collection_id' => $collection_id])->count();