有没有一种方法可以让Grails中的控制器访问函数? [英] Is there a way to make functions accessible across controllers in Grails?
问题描述
我希望能够创建全局函数,这意味着我可以跨控制器使用一个函数,类似于helper方法。
所以在一个控制器中,我可以做 有用的功能(字符串)
etc ...这可能吗?
我在src / groovy中创建了一个名为 SiteHelper
的类,我在正确的轨道上吗?我希望 SiteHelper
类的方法可以在整个控制器中使用。
http:// grails。 org / doc / latest / guide / services.html
I want to be able to create global functions, meaning a function I can use across controllers, kind of like helper methods.
So in one controller I could do
useful_function(string)
etc... Is this possible?
I did create a class in src/groovy called SiteHelper
, am I on the right track? I want the methods of the class SiteHelper
to be able to be used throughout controllers.
Yes, you're mostly on the right track. You may want to look at making it as a part of service layer.
http://grails.org/doc/latest/guide/services.html
这篇关于有没有一种方法可以让Grails中的控制器访问函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!