在sails中的所有控制器和服务中添加前缀
你好我新节点和帆,同时在我的代码做一些标准。 在sails.js我目前有这个,例如下面
api/ controllers/ TestController.js services/ TestServices.js
大多数情况下,我只能使用这种URL格式访问视图:
http://localhost/test/ http://localhost/test/<action>
如果我添加一些前缀到我的文件名,它会变成这样:
api/ controllers/ PrtestController.js services/ PrtestServices.js
通过右边的URL应该可以通过:
http://localhost/prtest/ http://localhost/prtest/<action>
问题:
1)如果我添加前缀到我所有的控制器和服务的文件名,是否有可能通过访问该url:
http://localhost/test/ http://localhost/test/<action>
没有添加前缀?
我想configurationconfig / routes.js为了达到这个通过编辑这样的东西:
'/test': { controller: 'PrtestController', action: '<action>' }, '/test/*': { controller: 'PrtestController' }
老实说,我还没有尝试过(这只是一个想法,在我的代码做出重大改变之前,否则我可能会搞砸了)
2)是否有可能在sails.js中有这个
PrtestController.js > prTestController.js
提前致谢!
编辑的问题
顺便说一句我正在使用默认的风帆configuration控制器的价值:
blueprints: { actions: true, rest: true, shortcuts: true, prefix: '' ...
}例子:(我的routes.js将如下所示)
'/test' : 'prTestController', '/test/action2' : 'prTestController:action2', '/test/action3' : 'prTestController:action3', '/test/action4' : 'prTestController:action4', '/test/action5' : 'prTestController:action5', '/test/action6' : 'prTestController:action6', '/test/action7' : 'prTestController:action7', '/test/action8' : 'prTestController:action8', '/test/action9' : 'prTestController:action9'
是否有可能的路线,如果URL是有/testing或/testing/ any_action会自动使用控制器prTestController或prTestController:any_action,分别?
对于#2,这是我的意思。
非常感谢!
-
是的,您必须编辑
config/routes.js
才能执行自定义路由 。
如果你的控制器被命名为PrtestController
,那么(如果被激活的话)蓝图会自动为你设置一个路由到host/prtest/
。 要覆盖这个,closures蓝图,并添加一些自定义路线。
在路线上打开文档如果您在理解Sails中的魔法方面有困难,我build议您closures所有的蓝图,或者至less使用不同的设置。 通过这样做,您必须手动configuration路由和操作。 当您了解蓝图的function和原因时,如果要使用它,请将其重新打开。
这是一个video教程 ,更详细地解释蓝图和路线。
-
不明白你的意思。 你想知道是否允许小写的控制器名? 如果是这样,是的,这不应该是一个问题。