widgets, widget menu
This commit is contained in:
parent
4c90d86509
commit
5b4676a4c0
34
kernel/Widget.php
Normal file
34
kernel/Widget.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace kernel;
|
||||
|
||||
class Widget
|
||||
{
|
||||
|
||||
protected CgView $cgView;
|
||||
protected array $data;
|
||||
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
$this->cgView = new CgView();
|
||||
$this->cgView->viewPath = ROOT_DIR . "/views/widgets";
|
||||
|
||||
$this->data = $data;
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
|
||||
public static function create(array $data = []): Widget
|
||||
{
|
||||
return new static($data);
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
35
kernel/models/Menu.php
Normal file
35
kernel/models/Menu.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\models;
|
||||
|
||||
use app\helpers\Debug;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Menu extends Model
|
||||
{
|
||||
protected $table = 'menu';
|
||||
protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status'];
|
||||
protected array $dates = ['deleted_at'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'parent_id' => 'Родительский пункт меню',
|
||||
'icon_file' => 'Путь к иконке',
|
||||
'icon_font' => 'Иконка',
|
||||
'label' => 'Заголовок',
|
||||
'url' => 'URL',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
public static function getChild(int $id)
|
||||
{
|
||||
$collection = Menu::where("parent_id", $id)->get();
|
||||
if (!$collection->isEmpty()){
|
||||
return $collection;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
17
kernel/widgets/MenuWidget.php
Normal file
17
kernel/widgets/MenuWidget.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\widgets;
|
||||
|
||||
use kernel\models\Menu;
|
||||
use kernel\Widget;
|
||||
|
||||
class MenuWidget extends Widget
|
||||
{
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$menu = Menu::where("parent_id", 0)->get();
|
||||
$this->cgView->render('/admin/menu.php', ['menu' => $menu]);
|
||||
}
|
||||
|
||||
}
|
34
migrations/2024_08_30_083939_create_menu_table.php
Normal file
34
migrations/2024_08_30_083939_create_menu_table.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
\kernel\App::$db->schema->create('menu', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('parent_id')->default(0);
|
||||
$table->string('icon_file', 255)->nullable();
|
||||
$table->string('icon_font', 255)->nullable();
|
||||
$table->string('label', 255);
|
||||
$table->string('url', 255);
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('menu');
|
||||
}
|
||||
};
|
@ -21,46 +21,7 @@
|
||||
<nav id="sidebar">
|
||||
<div class="p-4 pt-5">
|
||||
<a href="#" class="img logo rounded-circle mb-5" style="background-image: url(/resources/admin_theme/images/logo.jpg);"></a>
|
||||
<ul class="list-unstyled components mb-5">
|
||||
<li class="active">
|
||||
<a href="#homeSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">Home</a>
|
||||
<ul class="collapse list-unstyled" id="homeSubmenu">
|
||||
<li>
|
||||
<a href="#">Home 1</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">Home 2</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">Home 3</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">About</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#pageSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">Pages</a>
|
||||
<ul class="collapse list-unstyled" id="pageSubmenu">
|
||||
<li>
|
||||
<a href="#">Page 1</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">Page 2</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">Page 3</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">Portfolio</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">Contact</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
|
||||
<div class="footer">
|
||||
|
||||
</div>
|
||||
|
28
views/widgets/admin/menu.php
Normal file
28
views/widgets/admin/menu.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @var array $menu
|
||||
*/
|
||||
?>
|
||||
<ul class="list-unstyled components mb-5">
|
||||
<?php foreach ($menu as $item):
|
||||
$child = \kernel\models\Menu::getChild($item->id);
|
||||
if ($child): ?>
|
||||
<li>
|
||||
<a href="#item<?=$item->id?>" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"><?= $item->label ?></a>
|
||||
<ul class="collapse list-unstyled" id="item<?=$item->id?>">
|
||||
<?php foreach ($child as $subitem): ?>
|
||||
<li>
|
||||
<a href="<?= $subitem->url ?>"><?= $subitem->label ?></a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li>
|
||||
<a href="<?= $item->url ?>"><?= $item->label ?></a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user