widgets, widget menu
This commit is contained in:
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]);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user