2016-07-13 16 views
0

Grails 2.3.8 hier. Wenn ich mit bestimmten Controller-Aktionen verlinke, möchte ich einen Namespace in die URL vor dem Controller-Namen einfügen.setzen Namespace in URL

Zum Beispiel: Aufruf „app/Apfel/essen“ -> „app/admin/Apfel/essen“

Da viele dynamischen und statischen rüsteten Controller beteiligt sind, ich dachte, dass ich dies mit einigen tun können UrlMappings Ausdruck, aber ich weiß nicht, wie das geht.

habe ich versucht, ohne ohne Erfolg etwas wie folgt aus:

static mappings = { 
    "/apple/$action?/$id?" (redirect:"/admin/apple/$action?/$id?") 
} 

namespace = "admin" in der Arbeit AppleController doesnt mit aswell

Dank für Ratschläge

Antwort

0

Für das Beispiel

call "app/apple/eat" -> "app/admin/apple/eat" 

könnten Sie es über die Grails-App/Conf/UrlMappings.groovy w tun ith folgende Konfiguration (die für die gesamte Anwendung arbeitet als):

class UrlMappings { 

    static mappings = { 
     "/admin/$controller/$action?/$id?(.$format)?"{ 
      constraints { 
       // apply constraints here 
      } 
     } 

     "/"(view:"/index") 
     "500"(view:'/error') 
    } 
} 

mit dieser Konfiguration Ihre Controller sind erreichbar über:

http://localhost:8080/apple/admin/apple/eat/1 

etc. 

Oder!

Wenn Sie nur Apple unter dem Admin-Präfix haben würde, als Sie die folgende in Grails-app/conf/UrlMappings.groovy tun konnte:

class UrlMappings { 

    static mappings = { 
     "/admin/apple/$action?/$id?"(controller : "apple") 
     "/$controller/$action?/$id?(.$format)?"{ 
      constraints { 
       // apply constraints here 
      } 
     } 

     "/"(view:"/index") 
     "500"(view:'/error') 
    } 
} 

Oder!

Wenn Sie mehr Umleitungen haben, können Sie sie gruppieren:

static mappings = { 
    group("/admin") { 
     "/apple/$action?/$id?(.${format})?"(controller: 'apple') 
     "/peach/$action?/$id?(.${format})?"(controller: 'peach') 
    } 
    ... 
+0

ohh danke - die zweite „Oder“ hat für mich gearbeitet :) – pebbles