github.com/wangyougui/gf/v2@v2.6.5/net/ghttp/ghttp_request_view.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). 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/wangyougui/gf.
     6  
     7  package ghttp
     8  
     9  import "github.com/wangyougui/gf/v2/os/gview"
    10  
    11  // SetView sets template view engine object for this request.
    12  func (r *Request) SetView(view *gview.View) {
    13  	r.viewObject = view
    14  }
    15  
    16  // GetView returns the template view engine object for this request.
    17  func (r *Request) GetView() *gview.View {
    18  	view := r.viewObject
    19  	if view == nil {
    20  		view = r.Server.config.View
    21  	}
    22  	if view == nil {
    23  		view = gview.Instance()
    24  	}
    25  	return view
    26  }
    27  
    28  // Assigns binds multiple template variables to current request.
    29  func (r *Request) Assigns(data gview.Params) {
    30  	if r.viewParams == nil {
    31  		r.viewParams = make(gview.Params, len(data))
    32  	}
    33  	for k, v := range data {
    34  		r.viewParams[k] = v
    35  	}
    36  }
    37  
    38  // Assign binds a template variable to current request.
    39  func (r *Request) Assign(key string, value interface{}) {
    40  	if r.viewParams == nil {
    41  		r.viewParams = make(gview.Params)
    42  	}
    43  	r.viewParams[key] = value
    44  }