来自taglib的grails访问控制器 [英] grails access controller from taglib
本文介绍了来自taglib的grails访问控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从TagLib中访问当前控制器实例?例如:
class FooTagLib {
static namespace ='foo'
def msg = {attrs,body - >
//我可以在这里获得对当前控制器的引用吗?
$ b我想这样做是因为我存储了一些数据控制器的一个属性,并希望在TagLib中访问它。我知道这可能听起来很奇怪,但只是幽默我.... 解决方案在你的msg tagLib中:
grailsApplication.getArtefactByLogicalPropertyName('Controller',pageScope.controllerName)
Like Views,您可以通过 controllerName
和 actionName $ c $访问当前控制器和操作c>
Is it possible to access the current controller instance from within a TagLib? For example:
class FooTagLib {
static namespace = 'foo'
def msg = { attrs, body ->
// Can I get a reference to the current controller here?
}
}
I want to do this because I store some data in a property of the controller and want to access it within the TagLib. I realise this may sound strange, but just humour me....
解决方案 Inside your msg tagLib:
grailsApplication.getArtefactByLogicalPropertyName('Controller', pageScope.controllerName)
Like Views, you have access to the current controller and action through controllerName
and actionName
这篇关于来自taglib的grails访问控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文