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