请问在CMS中,在控制器的INDEX方法中如何添加两个不同的表格?
ModStartCMS V6.5.0
可以参考这个
<?php namespace App\Admin\Controller; use App\Model\DemoNews; use App\Model\DemoNewsCategory; use Illuminate\Routing\Controller; use ModStart\Admin\Concern\HasAdminDetail; use ModStart\Admin\Concern\HasAdminForm; use ModStart\Admin\Concern\HasAdminGrid; use ModStart\Admin\Layout\AdminPage; use ModStart\Core\Input\InputPackage; use ModStart\Core\Input\Request; use ModStart\Grid\Grid; use ModStart\Grid\GridFilter; use ModStart\Support\Concern\HasPageTitleInfo; use ModStart\Widget\Box; class DemoNewsMultiGridController extends Controller { use HasPageTitleInfo; use HasAdminGrid; use HasAdminForm; use HasAdminDetail; public function index(AdminPage $page) { $grid1 = $this->grid1(); $grid2 = $this->grid2(); if (Request::isPost()) { switch (InputPackage::buildFromInput()->getTrimString('_grid')) { case 'grid1': return $grid1->request(); case 'grid2': return $grid2->request(); } } return $page ->pageTitle('新闻管理(多个)') ->append(Box::make($grid1, '新闻分类')) ->append(Box::make($grid2, '新闻管理')); } public function grid1() { $grid = Grid::make(DemoNewsCategory::class); $grid->id('id', 'ID'); $grid->text('title', '标题'); $grid->title('新闻分类'); $grid->urlGrid(modstart_admin_url('demo/news_multi_grid', ['_grid' => 'grid1'])); $grid->canAdd(false)->canEdit(false)->canDelete(false); $grid->gridFilter(function (GridFilter $filter) { $filter->eq('id', 'ID'); $filter->like('title', '标题'); }); return $grid; } public function grid2() { $grid = Grid::make(DemoNews::class); $grid->id('id', 'ID'); $grid->select('categoryId', '分类')->optionModelTree(DemoNewsCategory::class); $grid->text('title', '标题'); $grid->richHtml('content', '内容'); $grid->title('新闻管理'); $grid->urlGrid(modstart_admin_url('demo/news_multi_grid', ['_grid' => 'grid2'])); $grid->canAdd(false)->canEdit(false)->canDelete(false); $grid->gridFilter(function (GridFilter $filter) { $filter->eq('id', 'ID'); $filter->like('title', '标题'); }); return $grid; } }
谢谢大佬!
在Grid中没有urlGrid方法 $grid->urlGrid(modstart_admin_url('demo/news_multi_grid', ['_grid' => 'grid1']));
等这两天最新的版本包
好的,谢谢。
QQ扫一扫联系
点击联系
2374926113
微信扫一扫联系
可以参考这个
谢谢大佬!
等这两天最新的版本包
好的,谢谢。