Controller

Index ▾

func RegisterController(c interface{}, methods []*MethodType)
type Controller
    func NewController(req *Request, resp *Response) *Controller
    func (c *Controller) FlashParams()
    func (c *Controller) Forbidden(msg string, objs ...interface{}) Result
    func (c *Controller) Message(message string, args ...interface{}) (value string)
    func (c *Controller) NotFound(msg string, objs ...interface{}) Result
    func (c *Controller) Redirect(val interface{}, args ...interface{}) Result
    func (c *Controller) Render(extraRenderArgs ...interface{}) Result
    func (c *Controller) RenderBinary(memfile io.Reader, filename string, delivery ContentDisposition, modtime time.Time) Result
    func (c *Controller) RenderError(err error) Result
    func (c *Controller) RenderFile(file *os.File, delivery ContentDisposition) Result
    func (c *Controller) RenderHtml(html string) Result
    func (c *Controller) RenderJson(o interface{}) Result
    func (c *Controller) RenderJsonP(callback string, o interface{}) Result
    func (c *Controller) RenderTemplate(templatePath string) Result
    func (c *Controller) RenderText(text string, objs ...interface{}) Result
    func (c *Controller) RenderXml(o interface{}) Result
    func (c *Controller) SetAction(controllerName, methodName string) error
    func (c *Controller) SetCookie(cookie *http.Cookie)
    func (c *Controller) Todo() Result
type ControllerType
    func (ct *ControllerType) Method(name string) *MethodType
type MethodArg
type MethodType

File

controller.go

func RegisterController

func RegisterController(c interface{}, methods []*MethodType)

Register a Controller and its Methods with Revel.

type Controller

type Controller struct {
    Name          string          // The controller name, e.g. "Application"
    Type          *ControllerType // A description of the controller type.
    MethodName    string          // The method name, e.g. "Index"
    MethodType    *MethodType     // A description of the invoked action type.
    AppController interface{}     // The controller that was instantiated.
    Action        string          // The fully qualified action name, e.g. "App.Index"

    Request  *Request
    Response *Response
    Result   Result

    Flash      Flash                  // User cookie, cleared after 1 request.
    Session    Session                // Session, stored in cookie, signed.
    Params     *Params                // Parameters from URL and form (including multipart).
    Args       map[string]interface{} // Per-request scratch space.
    RenderArgs map[string]interface{} // Args passed to the template.
    Validation *Validation            // Data validation helpers
}

func NewController

func NewController(req *Request, resp *Response) *Controller

func (*Controller) FlashParams

func (c *Controller) FlashParams()

func (*Controller) Forbidden

func (c *Controller) Forbidden(msg string, objs ...interface{}) Result

func (*Controller) Message

func (c *Controller) Message(message string, args ...interface{}) (value string)

Perform a message lookup for the given message name using the given arguments using the current language defined for this controller.

The current language is set by the i18n plugin.

func (*Controller) NotFound

func (c *Controller) NotFound(msg string, objs ...interface{}) Result

func (*Controller) Redirect

func (c *Controller) Redirect(val interface{}, args ...interface{}) Result

Redirect to an action or to a URL.

c.Redirect(Controller.Action)
c.Redirect("/controller/action")
c.Redirect("/controller/%d/action", id)

func (*Controller) Render

func (c *Controller) Render(extraRenderArgs ...interface{}) Result

Render a template corresponding to the calling Controller method. Arguments will be added to c.RenderArgs prior to rendering the template. They are keyed on their local identifier.

For example:

func (c Users) ShowUser(id int) revel.Result {
	 user := loadUser(id)
	 return c.Render(user)
}

This action will render views/Users/ShowUser.html, passing in an extra key-value "user": (User).

func (*Controller) RenderBinary

func (c *Controller) RenderBinary(memfile io.Reader, filename string, delivery ContentDisposition, modtime time.Time) Result

RenderBinary is like RenderFile() except that it instead of a file on disk, it renders data from memory (which could be a file that has not been written, the output from some function, or bytes streamed from somewhere else, as long it implements io.Reader). When called directly on something generated or streamed, modtime should mostly likely be time.Now().

func (*Controller) RenderError

func (c *Controller) RenderError(err error) Result

func (*Controller) RenderFile

func (c *Controller) RenderFile(file *os.File, delivery ContentDisposition) Result

Return a file, either displayed inline or downloaded as an attachment. The name and size are taken from the file info.

func (*Controller) RenderHtml

func (c *Controller) RenderHtml(html string) Result

Render html in response

func (*Controller) RenderJson

func (c *Controller) RenderJson(o interface{}) Result

Uses encoding/json.Marshal to return JSON to the client.

func (*Controller) RenderJsonP

func (c *Controller) RenderJsonP(callback string, o interface{}) Result

Renders a JSONP result using encoding/json.Marshal

func (*Controller) RenderTemplate

func (c *Controller) RenderTemplate(templatePath string) Result

A less magical way to render a template. Renders the given template, using the current RenderArgs.

func (*Controller) RenderText

func (c *Controller) RenderText(text string, objs ...interface{}) Result

Render plaintext in response, printf style.

func (*Controller) RenderXml

func (c *Controller) RenderXml(o interface{}) Result

Uses encoding/xml.Marshal to return XML to the client.

func (*Controller) SetAction

func (c *Controller) SetAction(controllerName, methodName string) error

SetAction sets the action that is being invoked in the current request. It sets the following properties: Name, Action, Type, MethodType

func (*Controller) SetCookie

func (c *Controller) SetCookie(cookie *http.Cookie)

func (*Controller) Todo

func (c *Controller) Todo() Result

Render a "todo" indicating that the action isn't done yet.

type ControllerType

type ControllerType struct {
    Type              reflect.Type
    Methods           []*MethodType
    ControllerIndexes [][]int // FieldByIndex to all embedded *Controllers
}

func (*ControllerType) Method

func (ct *ControllerType) Method(name string) *MethodType

Searches for a given exported method (case insensitive)

type MethodArg

type MethodArg struct {
    Name string
    Type reflect.Type
}

type MethodType

type MethodType struct {
    Name           string
    Args           []*MethodArg
    RenderArgNames map[int][]string
    // contains filtered or unexported fields
}