mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:30:54 +00:00
Merge remote-tracking branch 'astaxie/master'
This commit is contained in:
commit
053e7a6aa6
@ -38,6 +38,7 @@ type Controller struct {
|
|||||||
actionName string
|
actionName string
|
||||||
TplNames string
|
TplNames string
|
||||||
Layout string
|
Layout string
|
||||||
|
LayoutSections map[string]string // the key is the section name and the value is the template name
|
||||||
TplExt string
|
TplExt string
|
||||||
_xsrf_token string
|
_xsrf_token string
|
||||||
gotofunc string
|
gotofunc string
|
||||||
@ -161,6 +162,25 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
tplcontent, _ := ioutil.ReadAll(newbytes)
|
tplcontent, _ := ioutil.ReadAll(newbytes)
|
||||||
c.Data["LayoutContent"] = template.HTML(string(tplcontent))
|
c.Data["LayoutContent"] = template.HTML(string(tplcontent))
|
||||||
|
|
||||||
|
if c.LayoutSections != nil {
|
||||||
|
for sectionName, sectionTpl := range c.LayoutSections {
|
||||||
|
if (sectionTpl == "") {
|
||||||
|
c.Data[sectionName] = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sectionBytes := bytes.NewBufferString("")
|
||||||
|
err = BeeTemplates[sectionTpl].ExecuteTemplate(sectionBytes, sectionTpl, c.Data)
|
||||||
|
if err != nil {
|
||||||
|
Trace("template Execute err:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sectionContent, _ := ioutil.ReadAll(sectionBytes)
|
||||||
|
c.Data[sectionName] = template.HTML(string(sectionContent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ibytes := bytes.NewBufferString("")
|
ibytes := bytes.NewBufferString("")
|
||||||
err = BeeTemplates[c.Layout].ExecuteTemplate(ibytes, c.Layout, c.Data)
|
err = BeeTemplates[c.Layout].ExecuteTemplate(ibytes, c.Layout, c.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
20
router.go
20
router.go
@ -566,10 +566,12 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
for _, route := range p.fixrouters {
|
for _, route := range p.fixrouters {
|
||||||
n := len(requestPath)
|
n := len(requestPath)
|
||||||
if requestPath == route.pattern {
|
if requestPath == route.pattern {
|
||||||
runrouter = route.controllerType
|
|
||||||
findrouter = true
|
|
||||||
runMethod = p.getRunMethod(r.Method, context, route)
|
runMethod = p.getRunMethod(r.Method, context, route)
|
||||||
break
|
if runMethod != "" {
|
||||||
|
runrouter = route.controllerType
|
||||||
|
findrouter = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// pattern /admin url /admin 200 /admin/ 404
|
// pattern /admin url /admin 200 /admin/ 404
|
||||||
// pattern /admin/ url /admin 301 /admin/ 200
|
// pattern /admin/ url /admin 301 /admin/ 200
|
||||||
@ -608,11 +610,13 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
//reassemble query params and add to RawQuery
|
//reassemble query params and add to RawQuery
|
||||||
r.URL.RawQuery = url.Values(values).Encode()
|
r.URL.RawQuery = url.Values(values).Encode()
|
||||||
}
|
}
|
||||||
runrouter = route.controllerType
|
|
||||||
findrouter = true
|
|
||||||
context.Input.Params = params
|
|
||||||
runMethod = p.getRunMethod(r.Method, context, route)
|
runMethod = p.getRunMethod(r.Method, context, route)
|
||||||
break
|
if runMethod != "" {
|
||||||
|
runrouter = route.controllerType
|
||||||
|
context.Input.Params = params
|
||||||
|
findrouter = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -798,7 +802,7 @@ func (p *ControllerRegistor) getRunMethod(method string, context *beecontext.Con
|
|||||||
} else if m, ok = router.methods["*"]; ok {
|
} else if m, ok = router.methods["*"]; ok {
|
||||||
return m
|
return m
|
||||||
} else {
|
} else {
|
||||||
return strings.Title(method)
|
return ""
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return strings.Title(method)
|
return strings.Title(method)
|
||||||
|
Loading…
Reference in New Issue
Block a user