是否可以使用子文件夹对控制器进行分组? [英] Is it possible to group controllers in sails using subfolders?

查看:70
本文介绍了是否可以使用子文件夹对控制器进行分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算使用子文件夹来组织我的控制器,但是我不确定该怎么做.当我尝试使用类似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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆