是否可以使用子文件夹对控制器进行分组? [英] Is it possible to group controllers in sails using subfolders?
问题描述
我打算使用子文件夹来组织我的控制器,但是我不确定该怎么做.当我尝试使用类似admin/PageController.js并将其与路由连接时,我不断收到404错误.
您绝对可以做到这一点.诀窍是,控制器身份就是它的路径,在您的情况下为admin/PageController
.因此,config/routes.js
中的自定义路由将类似于:
'GET /admin/page/foo': 'admin/PageController.foo'
很棒的是,自动动作仍然可以工作,因此,如果控制器中有index
动作,则浏览到/admin/page
会自动运行它.
您还可以使用sails generate controller admin/page
创建类似的控制器.
I'm planning to organize my controllers in sails using subfolder but I'm not sure how to do it. When I tried using like admin/PageController.js and connect it with the route I keep getting a 404 error.
You can definitely do this. The trick is, the controller identity is its path, in your case admin/PageController
. So a custom route in config/routes.js
would be something like:
'GET /admin/page/foo': 'admin/PageController.foo'
The great thing is, automatic actions still work, so if you have an index
action in the controller then browsing to /admin/page
will automatically run it.
You can also create controllers like this with sails generate controller admin/page
.
这篇关于是否可以使用子文件夹对控制器进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!