Merge remote-tracking branch 'astaxie/master'
Showing
2 changed files
with
32 additions
and
8 deletions
| ... | @@ -38,6 +38,7 @@ type Controller struct { | ... | @@ -38,6 +38,7 @@ type Controller struct { |
| 38 | actionName string | 38 | actionName string |
| 39 | TplNames string | 39 | TplNames string |
| 40 | Layout string | 40 | Layout string |
| 41 | LayoutSections map[string]string // the key is the section name and the value is the template name | ||
| 41 | TplExt string | 42 | TplExt string |
| 42 | _xsrf_token string | 43 | _xsrf_token string |
| 43 | gotofunc string | 44 | gotofunc string |
| ... | @@ -161,6 +162,25 @@ func (c *Controller) RenderBytes() ([]byte, error) { | ... | @@ -161,6 +162,25 @@ func (c *Controller) RenderBytes() ([]byte, error) { |
| 161 | } | 162 | } |
| 162 | tplcontent, _ := ioutil.ReadAll(newbytes) | 163 | tplcontent, _ := ioutil.ReadAll(newbytes) |
| 163 | c.Data["LayoutContent"] = template.HTML(string(tplcontent)) | 164 | c.Data["LayoutContent"] = template.HTML(string(tplcontent)) |
| 165 | |||
| 166 | if c.LayoutSections != nil { | ||
| 167 | for sectionName, sectionTpl := range c.LayoutSections { | ||
| 168 | if (sectionTpl == "") { | ||
| 169 | c.Data[sectionName] = "" | ||
| 170 | continue | ||
| 171 | } | ||
| 172 | |||
| 173 | sectionBytes := bytes.NewBufferString("") | ||
| 174 | err = BeeTemplates[sectionTpl].ExecuteTemplate(sectionBytes, sectionTpl, c.Data) | ||
| 175 | if err != nil { | ||
| 176 | Trace("template Execute err:", err) | ||
| 177 | return nil, err | ||
| 178 | } | ||
| 179 | sectionContent, _ := ioutil.ReadAll(sectionBytes) | ||
| 180 | c.Data[sectionName] = template.HTML(string(sectionContent)) | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 164 | ibytes := bytes.NewBufferString("") | 184 | ibytes := bytes.NewBufferString("") |
| 165 | err = BeeTemplates[c.Layout].ExecuteTemplate(ibytes, c.Layout, c.Data) | 185 | err = BeeTemplates[c.Layout].ExecuteTemplate(ibytes, c.Layout, c.Data) |
| 166 | if err != nil { | 186 | if err != nil { | ... | ... |
| ... | @@ -566,10 +566,12 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) | ... | @@ -566,10 +566,12 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) |
| 566 | for _, route := range p.fixrouters { | 566 | for _, route := range p.fixrouters { |
| 567 | n := len(requestPath) | 567 | n := len(requestPath) |
| 568 | if requestPath == route.pattern { | 568 | if requestPath == route.pattern { |
| 569 | runrouter = route.controllerType | ||
| 570 | findrouter = true | ||
| 571 | runMethod = p.getRunMethod(r.Method, context, route) | 569 | runMethod = p.getRunMethod(r.Method, context, route) |
| 572 | break | 570 | if runMethod != "" { |
| 571 | runrouter = route.controllerType | ||
| 572 | findrouter = true | ||
| 573 | break | ||
| 574 | } | ||
| 573 | } | 575 | } |
| 574 | // pattern /admin url /admin 200 /admin/ 404 | 576 | // pattern /admin url /admin 200 /admin/ 404 |
| 575 | // pattern /admin/ url /admin 301 /admin/ 200 | 577 | // pattern /admin/ url /admin 301 /admin/ 200 |
| ... | @@ -608,11 +610,13 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) | ... | @@ -608,11 +610,13 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) |
| 608 | //reassemble query params and add to RawQuery | 610 | //reassemble query params and add to RawQuery |
| 609 | r.URL.RawQuery = url.Values(values).Encode() | 611 | r.URL.RawQuery = url.Values(values).Encode() |
| 610 | } | 612 | } |
| 611 | runrouter = route.controllerType | ||
| 612 | findrouter = true | ||
| 613 | context.Input.Params = params | ||
| 614 | runMethod = p.getRunMethod(r.Method, context, route) | 613 | runMethod = p.getRunMethod(r.Method, context, route) |
| 615 | break | 614 | if runMethod != "" { |
| 615 | runrouter = route.controllerType | ||
| 616 | context.Input.Params = params | ||
| 617 | findrouter = true | ||
| 618 | break | ||
| 619 | } | ||
| 616 | } | 620 | } |
| 617 | } | 621 | } |
| 618 | 622 | ||
| ... | @@ -798,7 +802,7 @@ func (p *ControllerRegistor) getRunMethod(method string, context *beecontext.Con | ... | @@ -798,7 +802,7 @@ func (p *ControllerRegistor) getRunMethod(method string, context *beecontext.Con |
| 798 | } else if m, ok = router.methods["*"]; ok { | 802 | } else if m, ok = router.methods["*"]; ok { |
| 799 | return m | 803 | return m |
| 800 | } else { | 804 | } else { |
| 801 | return strings.Title(method) | 805 | return "" |
| 802 | } | 806 | } |
| 803 | } else { | 807 | } else { |
| 804 | return strings.Title(method) | 808 | return strings.Title(method) | ... | ... |
-
Please register or sign in to post a comment