cakephp - 如何使用 CakePHP 3 烘焙管理(前缀)代码?

标签 cakephp admin crud cakephp-3.x cakephp-bake

谁能告诉我为管理后端创建 CRUD 的官方方法是什么?

在 CakePHP 2 中,烘焙代码在函数名称和 View 文件之前使用“admin_”进行扩展。 在 CakePHP 中,我似乎找不到任何关于它是如何完成的直接信息。烘焙控制台不再要求管理员。 在本主题中:https://github.com/cakephp/bake/issues/28我看到他们提到使用 --prefix 扩展名,但随后 Controller 被放置在单独的/Admin 文件夹中,而 CRUD 函数仍保留其正常名称。在说明书的某些部分 () 我仍然看到他们提到了像 admin_view 这样的函数。

那么谁能告诉我从 3.2 开始执行此操作的官方“Cake”方式是什么?

最佳答案

如果你想使用蛋糕烘焙创建 Controller 。您可以使用以下命令执行此操作:

bin/cake bake controller --prefix admin users

查看:

bin/cake bake template --prefix admin users

It creates the admin folder in the template directory, Then it creates the folder for users, then it includes the files. for admin prefix folder structure like template/admin/users/index.ctp

See official cookbook documentation

另外在您的 config/routes.php 中添加以下内容:

Router::prefix('admin', function ($routes) {
    $routes->connect('/', ['controller' => 'Users', 'action' => 'index']);
    $routes->extensions(['json', 'xml']);
    // All routes here will be prefixed with `/admin`
    // And have the prefix => admin route element added.
    $routes->fallbacks('DashedRoute');
});

关于cakephp - 如何使用 CakePHP 3 烘焙管理(前缀)代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38682379/

相关文章:

php - 更新管理页面上的行

python - 在 Django/python 中更改 "Authentication and Authorization"菜单的名称

php - CakePHP - 从 find() 方法中的 JOIN 中排除模型

Cakephp在组件中加载Appcontroller方法

php - 在 CakePHP View 中呈现 jQuery 代码时,如何使用 PHP 变量作为 <script> 标记的值?

php - 我的SQL语法错误,请与您的MariaDB检查?

php - 在 Laravel 中编辑和更新数据

cakephp - 保存后如何获取模型数据(CakePHP)

python - Django:如何调试这个管理错误?表单未呈现

php - 我怎样才能在 cakephp 中正确关联这些表?