xorgxx / neox-table-bundle
简化您管理 "crud" 集成的流程
Requires
- php: >=8.0
- doctrine/inflector: ^2.0
- nikic/php-parser: ^4.11
- symfony/asset: ^6.2
- symfony/config: ^5.4.7|^6.0
- symfony/console: ^5.4.7|^6.0
- symfony/dependency-injection: ^5.4.7|^6.0
- symfony/deprecation-contracts: ^2.2|^3
- symfony/filesystem: ^5.4.7|^6.0
- symfony/finder: ^5.4.3|^6.0
- symfony/framework-bundle: ^5.4.7|^6.0
- symfony/http-kernel: ^5.4.7|^6.0
- symfony/translation: ^6.2
- symfony/yaml: ^6.2
Requires (Dev)
- roave/security-advisories: dev-latest
Conflicts
- doctrine/doctrine-bundle: <2.4
- doctrine/orm: <2.10
- symfony/doctrine-bridge: <5.4
README
!!! 该包已停用 !! 考虑安装 NeoxMakeBundle !!!
此包提供了一种简单灵活的方式来管理您的应用程序中的 "crud" 渲染。其主要目标是简化您管理 "crud" 渲染的过程,并让您轻松配置不常见的选项。请注意,没有测试代码!
安装 BETA 版本 !!
使用 Composer 安装该包!!因为它仍然是 beta 版本!!
composer require xorgxx/neox-table-bundle
or
composer require xorgxx/neox-table-bundle:0.*
确保在您的 AppKernel 中注册了该包
Bundles.php <?php return [ ..... NeoxTable\NeoxTableBundle\NeoxTableBundle::class => ['all' => true], ..... ];
注意: 您可能需要使用 [ symfony composer dump-autoload ] 来重新加载自动加载
..... 完成 🎈
配置
除了安装 stimulus/turbo-ux 并正确设置外,无需进行任何配置!基于 Bootstrap 5 的基本 CSS,因此如果您在项目中安装了所有 Bs5 的 CSS 和 JS,它们将被应用。
如何在控制台中使用?symfony console neox:table:crud
The class name of the entity to create --> NeoxTable !! <-- CRUD (e.g. Deliciou
sGnome):
>
输入您想要 "crud" 的实体名称
Choose a name for your controller class (e.g. TestController) [TestController]:
>
输入您想要创建控制器的路径,例如:Admin\test\crud
Do you want to generate tests for the controller?. [Experimental] (yes/no) [no]
:
>
是或否生成测试?
那就是全部!它将为您生成所有内容
project
│ assets
│ bin
│ config
| ....
└─── src
│ └─── Controller
│ └─── Admin
| └─── test
| └─── crudController.php
| └─── Form
| └─── TestType.php
└─── templates
| └─── admin
| └─── test
| └─── _delete_form_html_twig
| └─── _form.html.twig
| └─── crud.html.twig
| └─── index.html.twig
| └─── show.html.twig
└─── translations
| └─── test.fr.yml
然后您需要在控制器中的列表中设置一行
└─── src
│ └─── Controller
│ └─── Admin
| └─── test
| └─── crudController.php
在您的控制器中导入类:buttonBuild 和 NeoxTableBuilder!
use NeoxTable\NeoxTableBundle\Controller\_NeoxCoreController
use NeoxTable\NeoxTableBundle\Service\NeoxTableBuilder;
use NeoxTable\NeoxTableBundle\Service\buttonBuild;
/** * @throws NonUniqueResultException */ #[Route('/', name: 'app_admin_post_crud_index', methods: ['GET'])] public function index(Request $request, PostRepository $postRepository): Response { // $header = (new buttonBuild()) // ->setLabel("Back Post") // ->setRef($this->generateUrl("app_admin_post_crud_index") ) // ->setClass("button-info bd-highlight") // ->setStyle("height: 30px", true) // ->setIcon("bi-arrow-left-square") // ->build(); $neoxTable = $this->getNeoxTableBuilder() ->filterFields("#, title, summary, author.email@user", "post") ->setEntity($postRepository->findAll()) // ->setActButton($header,"h") ->setActButton("@app_admin_post_crud") ; // 🔥 The magic happens here! 🔥 if ( $this->getNeoxTableBuilder()::checkTurbo($request) ) { return $this->render('@NeoxTable/neoxTable.html.twig',["neoxTable" => $neoxTable ]); } return $this->render('admin/post/crud/index.html.twig', [ 'neoxTable' => $neoxTable, ]); }
正如您所看到的: 🔥魔法就在这里!🔥是的,这是用 Turbo-ux 的魔法制作的
->filterFields("#, title, summary, author.email@user", "post", [...]) <----- !!here
添加您需要在渲染表格中看到的全部字段。*如果您在实体中有关系:author.email@user [@ 用于为翻译器提供域名]
注意: 您可以在标题或表格列中手动添加任何按钮。还将出现新的语法,以便按您希望的方式添加按钮!
$header = (new buttonBuild())
->setLabel("Back Post")
->setRef($this->generateUrl("app_admin_post_crud_index") )
->setClass("button-info bd-highlight")
->setStyle("height: 30px", true)
->setIcon("bi-arrow-left-square")
->build();
New syntax :
$header = (new buttonBuild())
->setType("@")
->setAdd('<a href="/site-quotation" class="button m-0 button-circle button-large text-white" style="background-color: #084678;">Estimation gratuite ...</a>')
->build();
!!! Important NOTE !!!
to set turbo mode setTurbo() ->setTurbo("data-turbo='true'")
TODO additionnal data-xxx
them to send to builder :
$this->setButton($header, [Tag {a} to create action button; {h} to create header button]);
这为您生成了所有标准的 CRUD 按钮:添加 - 删除 - 锚定 - 编辑 -- 返回
->setActButton("@app_admin_post_crud") --> all button header and table colonne
->setActButton("#app_admin_post_crud") --> only button table colonne
如果您需要添加特殊的 Js 或 css
->styling([...template.html.twig...])
在操作栏上添加投票者:如果在您的项目中设置了实体的投票者,它将识别
public const NEW = 'NEW';
public const EDIT = 'EDIT';
public const PIN = 'PIN';
public const VIEW = 'VIEW';
public const DELETE = 'DELETE';
现在可以添加 "filter" 和 "function" Twig
->filterFields("#, title, description, position, faqsDomaine.value, category#join('|')|raw", "faq")
or to give custome one
->filterFields("#, title, description, position, faqsDomaine#enum, category#join('|')", "faq")
贡献
如果您想为此包做出贡献(谢谢!),以下是一些指南
- 请遵守 Symfony 指南
- 测试一切!请在修复尚未涵盖的 bug 时,在 tests/ 目录中添加测试用例
- 您修复了一个之前未涵盖的 bug
- 您添加了一个新功能
- 您看到代码正在运行,但没有任何测试覆盖(天堂里有一个特别的地方为您预留)
- ->> 🔥🔥 28/07/2023 必须根据新版本的 Makebundle symfony 更新 Controller.tpl.php,因为不再有 "repositoryHasSaveAndRemoveMethode" 方法
待办事项
- Packagist