mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 17:10:50 +00:00
TplNames renamed TplName ,fix #1229,Remember modify bee tool.
This commit is contained in:
parent
80912b6210
commit
4c0c0ec2a7
@ -68,7 +68,7 @@ type Controller struct {
|
||||
AppController interface{}
|
||||
|
||||
// template data
|
||||
TplNames string
|
||||
TplName string
|
||||
Layout string
|
||||
LayoutSections map[string]string // the key is the section name and the value is the template name
|
||||
TplExt string
|
||||
@ -105,7 +105,7 @@ type ControllerInterface interface {
|
||||
// Init generates default values of controller operations.
|
||||
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
||||
c.Layout = ""
|
||||
c.TplNames = ""
|
||||
c.TplName = ""
|
||||
c.controllerName = controllerName
|
||||
c.actionName = actionName
|
||||
c.Ctx = ctx
|
||||
@ -200,12 +200,12 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
||||
//if the controller has set layout, then first get the tplname's content set the content to the layout
|
||||
var buf bytes.Buffer
|
||||
if c.Layout != "" {
|
||||
if c.TplNames == "" {
|
||||
c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
||||
if c.TplName == "" {
|
||||
c.TplName = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
||||
}
|
||||
|
||||
if BConfig.RunMode == DEV {
|
||||
buildFiles := []string{c.TplNames}
|
||||
buildFiles := []string{c.TplName}
|
||||
if c.LayoutSections != nil {
|
||||
for _, sectionTpl := range c.LayoutSections {
|
||||
if sectionTpl == "" {
|
||||
@ -216,10 +216,10 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
||||
}
|
||||
BuildTemplate(BConfig.WebConfig.ViewsPath, buildFiles...)
|
||||
}
|
||||
if _, ok := BeeTemplates[c.TplNames]; !ok {
|
||||
panic("can't find templatefile in the path:" + c.TplNames)
|
||||
if _, ok := BeeTemplates[c.TplName]; !ok {
|
||||
panic("can't find templatefile in the path:" + c.TplName)
|
||||
}
|
||||
err := BeeTemplates[c.TplNames].ExecuteTemplate(&buf, c.TplNames, c.Data)
|
||||
err := BeeTemplates[c.TplName].ExecuteTemplate(&buf, c.TplName, c.Data)
|
||||
if err != nil {
|
||||
Trace("template Execute err:", err)
|
||||
return nil, err
|
||||
@ -252,17 +252,17 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
if c.TplNames == "" {
|
||||
c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
||||
if c.TplName == "" {
|
||||
c.TplName = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
||||
}
|
||||
if BConfig.RunMode == DEV {
|
||||
BuildTemplate(BConfig.WebConfig.ViewsPath, c.TplNames)
|
||||
BuildTemplate(BConfig.WebConfig.ViewsPath, c.TplName)
|
||||
}
|
||||
if _, ok := BeeTemplates[c.TplNames]; !ok {
|
||||
panic("can't find templatefile in the path:" + c.TplNames)
|
||||
if _, ok := BeeTemplates[c.TplName]; !ok {
|
||||
panic("can't find templatefile in the path:" + c.TplName)
|
||||
}
|
||||
buf.Reset()
|
||||
err := BeeTemplates[c.TplNames].ExecuteTemplate(&buf, c.TplNames, c.Data)
|
||||
err := BeeTemplates[c.TplName].ExecuteTemplate(&buf, c.TplName, c.Data)
|
||||
if err != nil {
|
||||
Trace("template Execute err:", err)
|
||||
return nil, err
|
||||
|
@ -61,8 +61,8 @@ func TestNamespaceNest(t *testing.T) {
|
||||
ns.Namespace(
|
||||
NewNamespace("/admin").
|
||||
Get("/order", func(ctx *context.Context) {
|
||||
ctx.Output.Body([]byte("order"))
|
||||
}),
|
||||
ctx.Output.Body([]byte("order"))
|
||||
}),
|
||||
)
|
||||
AddNamespace(ns)
|
||||
BeeApp.Handlers.ServeHTTP(w, r)
|
||||
@ -79,8 +79,8 @@ func TestNamespaceNestParam(t *testing.T) {
|
||||
ns.Namespace(
|
||||
NewNamespace("/admin").
|
||||
Get("/order/:id", func(ctx *context.Context) {
|
||||
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
||||
}),
|
||||
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
||||
}),
|
||||
)
|
||||
AddNamespace(ns)
|
||||
BeeApp.Handlers.ServeHTTP(w, r)
|
||||
@ -124,8 +124,8 @@ func TestNamespaceFilter(t *testing.T) {
|
||||
ctx.Output.Body([]byte("this is Filter"))
|
||||
}).
|
||||
Get("/user/:id", func(ctx *context.Context) {
|
||||
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
||||
})
|
||||
ctx.Output.Body([]byte(ctx.Input.Param(":id")))
|
||||
})
|
||||
AddNamespace(ns)
|
||||
BeeApp.Handlers.ServeHTTP(w, r)
|
||||
if w.Body.String() != "this is Filter" {
|
||||
|
@ -24,11 +24,11 @@ type MainController struct {
|
||||
}
|
||||
|
||||
func (this *MainController) Get() {
|
||||
this.TplNames = "index.tpl"
|
||||
this.TplName = "index.tpl"
|
||||
}
|
||||
|
||||
func (this *MainController) Post() {
|
||||
this.TplNames = "index.tpl"
|
||||
this.TplName = "index.tpl"
|
||||
|
||||
this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
|
||||
}
|
||||
|
@ -37,11 +37,11 @@
|
||||
// }
|
||||
//
|
||||
// func (this *MainController) Get() {
|
||||
// this.TplNames = "index.tpl"
|
||||
// this.TplName = "index.tpl"
|
||||
// }
|
||||
//
|
||||
// func (this *MainController) Post() {
|
||||
// this.TplNames = "index.tpl"
|
||||
// this.TplName = "index.tpl"
|
||||
//
|
||||
// this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user