feat: add icon field to frontend menu

master
Manop Kongoon 2026-02-27 09:32:45 +07:00
parent 8ef18d6d30
commit 6427712512
6 changed files with 42 additions and 3 deletions

View File

@ -3,3 +3,4 @@
- Fixed incorrect aggregation in monthly and yearly statistics.
- Adjusted footer contact information font style for better readability.
- Added frontend menu management system in administrator module (navbar and left menu positions).
- Added 'icon' support for frontend menu management.

View File

@ -15,10 +15,13 @@ use yii\helpers\ArrayHelper;
<?php $form = ActiveForm::begin(); ?>
<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-md-6">
<div class="col-md-4">
<?= $form->field($model, 'icon')->textInput(['maxlength' => true, 'placeholder' => 'fa fa-home']) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'link')->textInput(['maxlength' => true]) ?>
</div>
</div>

View File

@ -28,8 +28,10 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'name',
'format' => 'raw',
'value' => function ($model) {
return ($model->parent_id ? '— ' : '') . $model->name;
$icon = $model->icon ? Html::tag('i', '', ['class' => $model->icon]) . ' ' : '';
return ($model->parent_id ? '— ' : '') . $icon . $model->name;
}
],
'link',

View File

@ -38,6 +38,11 @@ $this->params['breadcrumbs'][] = $this->title;
'value' => $model->parent ? $model->parent->name : '-- เป็นเมนูหลัก --',
],
'name',
[
'attribute' => 'icon',
'format' => 'raw',
'value' => $model->icon ? Html::tag('i', '', ['class' => $model->icon]) . ' (<code>' . Html::encode($model->icon) . '</code>)' : null,
],
'link',
[
'attribute' => 'position',

View File

@ -11,6 +11,7 @@ use yii\behaviors\TimestampBehavior;
* @property int $id
* @property int|null $parent_id
* @property string $name
* @property string|null $icon
* @property string|null $link
* @property string $position navbar, left_menu
* @property int|null $sort_order
@ -50,6 +51,7 @@ class CmsMenuFrontend extends \yii\db\ActiveRecord
[['parent_id', 'sort_order', 'status', 'created_at', 'updated_at'], 'integer'],
[['name', 'position'], 'required'],
[['name', 'link'], 'string', 'max' => 255],
[['icon'], 'string', 'max' => 100],
[['position'], 'string', 'max' => 50],
[['parent_id'], 'exist', 'skipOnError' => true, 'targetClass' => CmsMenuFrontend::class, 'targetAttribute' => ['parent_id' => 'id']],
];
@ -64,6 +66,7 @@ class CmsMenuFrontend extends \yii\db\ActiveRecord
'id' => 'ID',
'parent_id' => 'เมนูหลัก',
'name' => 'ชื่อเมนู',
'icon' => 'ไอคอน (เช่น fa fa-home)',
'link' => 'ลิงก์',
'position' => 'ตำแหน่ง',
'sort_order' => 'ลำดับ',

View File

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Handles adding columns to table `{{%cms_menu_frontend}}`.
*/
class m260227_023007_add_icon_column_to_cms_menu_frontend_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%cms_menu_frontend}}', 'icon', $this->string(100)->after('name'));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%cms_menu_frontend}}', 'icon');
}
}