开发者

Use controllers globally in Grails

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 tem开发者_运维百科plate 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?


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


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 :-)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜