在 Grails 中全局使用控制器

发布于 2024-10-12 21:39:02 字数 695 浏览 9 评论 0原文

我是 Grails 新手,正在尝试用它构建一个 CMS。 我希望导航菜单从数据库中读取,以便新页面将自动在导航中获取链接。我一直在阅读Grails:使用index.gsp中的控制器和相关问题,但答案似乎对我不起作用。 :(

我创建了一个名为 Navigation 的域类和一个名为 _header 的模板。

在“Navigation/list”命名空间中一切正常,但在外部我无法访问导航数据。

我已经设置了 url 映射,如下所示:

class UrlMappings {
    static mappings = {
        "/$controller/$action?/$id?"{
            constraints {
                // apply constraints here
            }
        }
        "/"(controller : "Navigation", action : "list")
        "/"(view:"/index")
        "500"(view:'/error')
    }
}

但这似乎不起作用。有什么线索可以说明问题所在吗?

I'm new to Grails and am trying to build a CMS with it.
I want the navigation menu to read from the database so a new page will automatically get a link in the navigation. I've been reading Grails: use controller from index.gsp and related questions, but the answers don't seem to work for me. :(

I've created a domain class named Navigation and a template called _header.

In the "Navigation/list" namespace everything works fine, but outside I can't get to the Navigation data.

I've setup url mapping like so:

class UrlMappings {
    static mappings = {
        "/$controller/$action?/$id?"{
            constraints {
                // apply constraints here
            }
        }
        "/"(controller : "Navigation", action : "list")
        "/"(view:"/index")
        "500"(view:'/error')
    }
}

But that doesn't seem to work. Any clues on what could be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

睡美人的小仙女 2024-10-19 21:39:02

您有两个“/”映射,新的和原始的:“/”(view:“/index”) - 对于初学者,您需要删除另一个。

You have two mappings for "/", your new one and the original one: "/"(view:"/index") - for starters you'll need to remove the other one.

神魇的王 2024-10-19 21:39:02

不确定您是否意识到这一点,Grails 中有一个内置的开源 CMS,名为 Weceem。如果您需要将其用作另一个 Grails 应用程序的一部分,还有一个 Weceem 的 grails 插件,因此您可以将其用作应用程序的一部分。

在构建一个全新的 CMS 之前可能值得研究一下:-)

Not sure if you are aware of this, but there is an open source CMS built in Grails called Weceem. If you need to use it as part of another Grails application, there is also a grails plug in for Weceem, so you can use it as part of your app.

It might worth looking into it before building a complete new CMS :-)

调妓 2024-10-19 21:39:02

我看问题完全错误,urlmapping 只使index.gsp 重定向到导航/列表。我正在寻找的是

DomainClass.findAll( String query )

在 g:each 标签中使用的属性,

<g:each in="${Navigation.findAll('from Navigation as n where n.css=?', ['ctBoven'])}" var="oNavigation" status="i">

这允许我从任何页面读取任何数据库。

I was looking at the problem all wrong, urlmapping only made the index.gsp redirect to navigation/list. What I was looking for was the

DomainClass.findAll( String query )

propertie to use in the g:each tag

<g:each in="${Navigation.findAll('from Navigation as n where n.css=?', ['ctBoven'])}" var="oNavigation" status="i">

This allows me to read any database from any page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文