c3bc2bed by astaxie

add methodName to fix #380 & arrangement the router

1 parent 7b27b7fe
...@@ -29,21 +29,22 @@ var ( ...@@ -29,21 +29,22 @@ var (
29 ) 29 )
30 30
31 type Controller struct { 31 type Controller struct {
32 Ctx *context.Context 32 Ctx *context.Context
33 Data map[interface{}]interface{} 33 Data map[interface{}]interface{}
34 ChildName string 34 controllerName string
35 TplNames string 35 actionName string
36 Layout string 36 TplNames string
37 TplExt string 37 Layout string
38 _xsrf_token string 38 TplExt string
39 gotofunc string 39 _xsrf_token string
40 CruSession session.SessionStore 40 gotofunc string
41 XSRFExpire int 41 CruSession session.SessionStore
42 AppController interface{} 42 XSRFExpire int
43 AppController interface{}
43 } 44 }
44 45
45 type ControllerInterface interface { 46 type ControllerInterface interface {
46 Init(ct *context.Context, childName string, app interface{}) 47 Init(ct *context.Context, controllerName, actionName string, app interface{})
47 Prepare() 48 Prepare()
48 Get() 49 Get()
49 Post() 50 Post()
...@@ -56,11 +57,12 @@ type ControllerInterface interface { ...@@ -56,11 +57,12 @@ type ControllerInterface interface {
56 Render() error 57 Render() error
57 } 58 }
58 59
59 func (c *Controller) Init(ctx *context.Context, childName string, app interface{}) { 60 func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
60 c.Data = make(map[interface{}]interface{}) 61 c.Data = make(map[interface{}]interface{})
61 c.Layout = "" 62 c.Layout = ""
62 c.TplNames = "" 63 c.TplNames = ""
63 c.ChildName = childName 64 c.controllerName = controllerName
65 c.actionName = actionName
64 c.Ctx = ctx 66 c.Ctx = ctx
65 c.TplExt = "tpl" 67 c.TplExt = "tpl"
66 c.AppController = app 68 c.AppController = app
...@@ -123,7 +125,7 @@ func (c *Controller) RenderBytes() ([]byte, error) { ...@@ -123,7 +125,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
123 //if the controller has set layout, then first get the tplname's content set the content to the layout 125 //if the controller has set layout, then first get the tplname's content set the content to the layout
124 if c.Layout != "" { 126 if c.Layout != "" {
125 if c.TplNames == "" { 127 if c.TplNames == "" {
126 c.TplNames = c.ChildName + "/" + strings.ToLower(c.Ctx.Request.Method) + "." + c.TplExt 128 c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
127 } 129 }
128 if RunMode == "dev" { 130 if RunMode == "dev" {
129 BuildTemplate(ViewsPath) 131 BuildTemplate(ViewsPath)
...@@ -150,7 +152,7 @@ func (c *Controller) RenderBytes() ([]byte, error) { ...@@ -150,7 +152,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
150 return icontent, nil 152 return icontent, nil
151 } else { 153 } else {
152 if c.TplNames == "" { 154 if c.TplNames == "" {
153 c.TplNames = c.ChildName + "/" + strings.ToLower(c.Ctx.Request.Method) + "." + c.TplExt 155 c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
154 } 156 }
155 if RunMode == "dev" { 157 if RunMode == "dev" {
156 BuildTemplate(ViewsPath) 158 BuildTemplate(ViewsPath)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!