Yii2 Notlarım

Yii2

DetailView widget Html value

[
‘label’ => $model->getAttributeLabel(“status”),
‘value’ => function ($model) {
if ($model->status== 1) {
return Html::a(Yii::t(‘app’, ‘AKTİF’), [‘Site/index’, ‘id’ => $model->id], [‘class’ => ‘btn btn-success’]);
} else {
return Html::a(Yii::t(‘app’, ‘PASİF’), [‘Site/index’, ‘id’ => $model->id], [‘class’ => ‘btn btn-danger’]);
}
},
‘format’ => ‘html’,
],

Devamı

Model Label:

$model->getAttributeLabel('name');

Dropdown:

echo $form->field($model, ’category’)->dropdownList([
1 => ’item 1’,
2 => ’item 2’
],
[’prompt’=>’Select Category’]
);

Yii2 – Paggination

View

use yii\widgets\LinkPager;
.....
echo LinkPager::widget([
'pagination' => $pagination,
]);


Controller:


use yii\data\Pagination;
....
$mediaData = FileManager::find()->where(['file_status' => 1]);
$count = $mediaData->count();
$pagination = new Pagination(['totalCount' => $count]);
....
return $this->renderPartial('files',
[
'pagination'=>$pagination,
]);

Yii2- Redirect Back

return $this->redirect(Yii::$app->request->referrer ?: Yii::$app->homeUrl);

Html::DropDownList For Yii2

echo Html::dropDownList('select_name', [1, 3, 5], ArrayHelper::map($content, 'ID', 'VALUE_DEG'), [
'multiple' => 'multiple',
'options' => ['value1' => ['disabled' => true, 'class' => 'yourClass', 'style'=> 'yourStyle'],
'value2' => ['label' => 'value 2'],
]

Yii2 GridView Action Button

[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {update} {delete} {myButton}',
// the default buttons + your custom button
'buttons' => [
'myButton' => function (
$url,
$model,
$key
) { // render your custom button
return Html::a(
'',
$url,
[
'title' => 'Download',
'data-pjax' => '0',
]
);
},
],
],