在router的init方法中设置lay等字段,为什么不起作用呢??
```golang
func init() {
mainController := &controllers.MainController{}
mainController.Layout = "layout_blog.tpl"
mainController.LayoutSections = map[string]string{
"HtmlHead": "html_head.tpl",
"Scripts": "scripts.tpl",
"Sidebar": "",
}
fmt.Println(mainController.LayoutSections)
beego.Router("/", mainController)
}
```
不过在MainController的Get方法中设置,是可以工作的
```galang
func (this *MainController) Get() {
this.Layout = "layout_blog.tpl"
this.LayoutSections = map[string]string{
"HtmlHead": "html_head.tpl",
"Scripts": "scripts.tpl",
"Sidebar": "",
}
this.TplName = "index.tpl"
}
```
请各位大神不吝赐教!!
有疑问加站长微信联系(非本文作者)