ghttp_request_view.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package ghttp
  7. import "github.com/gogf/gf/os/gview"
  8. // SetView sets template view engine object for this request.
  9. func (r *Request) SetView(view *gview.View) {
  10. r.viewObject = view
  11. }
  12. // GetView returns the template view engine object for this request.
  13. func (r *Request) GetView() *gview.View {
  14. view := r.viewObject
  15. if view == nil {
  16. view = r.Server.config.View
  17. }
  18. if view == nil {
  19. view = gview.Instance()
  20. }
  21. return view
  22. }
  23. // Assigns binds multiple template variables to current request.
  24. func (r *Request) Assigns(data gview.Params) {
  25. if r.viewParams == nil {
  26. r.viewParams = make(gview.Params, len(data))
  27. }
  28. for k, v := range data {
  29. r.viewParams[k] = v
  30. }
  31. }
  32. // Assign binds a template variable to current request.
  33. func (r *Request) Assign(key string, value interface{}) {
  34. if r.viewParams == nil {
  35. r.viewParams = make(gview.Params)
  36. }
  37. r.viewParams[key] = value
  38. }