gf/net/ghttp/ghttp_request_view.go

45 lines
1.1 KiB
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// 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/gogf/gf.
package ghttp
2021-10-11 21:41:56 +08:00
import "github.com/gogf/gf/v2/os/gview"
2019-12-10 21:14:15 +08:00
// SetView sets template view engine object for this request.
func (r *Request) SetView(view *gview.View) {
2019-12-10 21:14:15 +08:00
r.viewObject = view
}
2019-12-10 21:14:15 +08:00
// GetView returns the template view engine object for this request.
func (r *Request) GetView() *gview.View {
2019-12-10 21:14:15 +08:00
view := r.viewObject
if view == nil {
view = r.Server.config.View
}
if view == nil {
2019-11-26 15:12:58 +08:00
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
}