scrm-go

base_view_controller.go 654B

12345678910111213141516171819202122232425262728293031323334353637
  1. package controllers
  2. type BaseViewController struct {
  3. BaseController
  4. }
  5. // 设置模板
  6. // 第一个参数模板,第二个参数为layout
  7. func (this *BaseViewController) SetTpl(template ...string) {
  8. var tplName string
  9. layout := ""
  10. switch {
  11. case len(template) == 1:
  12. tplName = template[0]
  13. case len(template) == 2:
  14. tplName = template[0]
  15. layout = template[1]
  16. default:
  17. tplName = "index.tpl"
  18. }
  19. this.Layout = layout
  20. this.TplName = tplName
  21. }
  22. // 重定向
  23. func (this *BaseViewController) Redirect302(url string) {
  24. this.Redirect(url, 302)
  25. this.StopRun()
  26. }
  27. // 错误页面
  28. func (this *BaseViewController) Abort404() {
  29. this.Abort("404")
  30. }