Controller_Base is an abstract base class for implementing controllers.
Controllers are expected to provide one or more public methods which require no arguments to be passed. All such public methods are considered actions of the controller (unless the method name has been passed to hide_action()). Actions are automatically invoked to service a request depending on the request URL and the configured routing in the application.
For example, with default routing in place, a request to the URL "/hello" would invoke the index method of this controller:
Unless the action explicitly renders a response, the render_action() method is called automatically when the method returns. By default, this would expect a view template to exist at "views/hello/index.tpl". That might look something like:
Variables may be passed to views through the use of instance variables. All public instances variables of your controller become variables of the same name in the view. So if we did this in our controller:
The view file could then make use of the variable, like so:
Note that undeclared instance variables will be treated as public variables. You can prevent instance variables from being available to the view by specifically declaring them either protected or private:
So that in the view this would not output any date or time information in the second paragraph:
Located in /controller/lib/Controller/Base.php (line 131)
Constructor
Accessor for this controller's action name
Add an event listener to this class.
Options for the listener are:
Register a method on this class to be called before any request is processed.
Options for the filter are:
Determine if an method can allowably be invoked as an action
Assigns all public properties of the class as local variables in the template
Register a method on this class to be called before any request is processed. If the method that is called returns false, all processing of the request is stopped.
Options for the filter are:
Enable caching for one or more actions on this controller. Accepts one or more action names as parameters or an array of action names.
Actions may be conditionally cached by passing a list of options as the last argument to caches_action and specifying a callback with the 'if' option.
For example:
The above would then cause the controller to call the method not_logged_in to determine if the index and show actions would be cached.
Return the cache options to use when caching an action
Returns the name of the controller. For ExampleController this returns 'example'.
Deliver a multipart/alternative email
Additional options:
Expire a cached action. Defaults to the current action.
For example:
Would expire any cached content for the index action.
Expire a cached fragment. Defaults to the current action and a null fragment name.
For example:
Would expire a block in the index view that looked like:
Notifies any registered event listeners
Return a flash message
Returns the current authenticity token to use in forms in conjunction with the protect_from_forgery() filter.
Process an incoming HTTP request
Returns the list of headers which have been output that should be cached (or an empty list if none).
Return a list of all public methods which have been protected from use as an action.
Accepts the names of one or more public methods which are protected from invocation as an action.
Accessor for this controller's layout name
Return a logger instance for the class
A convenience method that calls Support_Util::model()
This method exists purely for more concise code creation. All three of the examples below perform the same operation:
Return a 404 not found message back.
Handle an exception thrown in an action.
Perform the current action. This method is intended only for use by handle_request().
Prepare template and layout for rendering.
If the request is not a GET request and does not contain the
expected token, outputs a 403 Forbidden error and returns false, otherwise returns true. This is intended to be uses as a before filter to help in the prevention of cross-site request forgery attacks.
Output a redirect header to the browser
The $url parameter may be specified as a string, or passed as an array. If an array it provided, it is passed to the url_for() method to produce a URL for the redirect.
Remove an event listener from this class.
Accessor for this controller's rendered flag
Render the template for the action
Options are:
Render an error document
Options are:
Render the template as a string.
If HTTPS is not the current protocol, outputs a redirect header to this URL using HTTPS and returns false, otherwise returns true. Convenient for use as a before filter on pages requiring HTTPS.
If the current request method is not POST, outputs a 405 Method Not Allowed error and returns false, otherwise returns true. This is convenient for use in a conditional before filter to limit some actions to post only.
This method sets the controller's action
Set the error flag for the controller
Set a flash message
This method sets the path to the layout to be used.
A value of 'application' will expect a corresponding file named 'views/layouts/application.tpl'.
This method sets the controller's rendered flag
Set the routing instance currently in use
Set various template variables if they have not been set explicitly.
Returns the current template cache ID, in case you want to vary the cached output based on some condition.
Returns the current template compile ID, in case this controller changes the template directory.
Return the URL for a given set of parameters.
For example:
Will return "/session/login" if you have configured a route like:
If a URL cannot be determined, an exception is thrown.
Returns true if the given action name will be cached
Invoked when an attempt is made to retrieve the value of an undeclared instance variable
Invoked when an attempt is made to call isset or empty for an undeclared instance variable
Invoked when an attempt is made to set an undeclared instance variable
Invoked when an attempt is made to unset an undeclared instance variable
Documentation generated on Wed, 25 Apr 2012 09:46:40 -0700 by phpDocumentor 1.4.3