有没有一种方法可以让Grails中的控制器访问函数? [英] Is there a way to make functions accessible across controllers in Grails?

查看:149
本文介绍了有没有一种方法可以让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屋!

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