Controller_BaseController_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)
mixed
$action
= NULL (line 135)
mixed
$event_listeners
= array() (line 134)
mixed
$flash
= NULL (line 136)
mixed
$hidden_actions
= array('__construct'=>1,
mixed
$layout
= NULL (line 133)
mixed
$logger
= NULL (line 138)
mixed
$rendered
= false (line 137)
mixed
$_action_method
= null (line 144)
mixed
$_cache_actions
= array() (line 142)
mixed
$_cache_headers
= array('content-type'=>1,
mixed
$_is_error
= false (line 141)
mixed
$_routing
= null (line 139)
mixed
$_runtime_variables
= array() (line 140)
mixed
$_will_cache_action
= false (line 143)
Constructor __construct (line 165)
Constructor
action (line 173)
Accessor for this controller's action name
add_event_listener (line 936)
Add an event listener to this class.
Options for the listener are:
after_filter (line 855)
Register a method on this class to be called before any request is processed.
Options for the filter are:
allowed_action (line 601)
Determine if an method can allowably be invoked as an action
assign_template_vars (line 769)
Assigns all public properties of the class as local variables in the template
before_filter (line 840)
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:
caches_action (line 511)
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.
cache_options (line 915)
Return the cache options to use when caching an action
controller_name (line 240)
Returns the name of the controller. For ExampleController this returns 'example'.
deliver_mail (line 700)
Deliver a multipart/alternative email
Additional options:
expire_action (line 303)
Expire a cached action. Defaults to the current action.
For example:
Would expire any cached content for the index action.
expire_fragment (line 331)
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:
fire_event (line 990)
Notifies any registered event listeners
flash (line 279)
Return a flash message
form_authenticity_token (line 393)
Returns the current authenticity token to use in forms in conjunction with the protect_from_forgery() filter.
handle_request (line 400)
Process an incoming HTTP request
headers_for_cache (line 553)
Returns the list of headers which have been output that should be cached (or an empty list if none).
hidden_actions (line 590)
Return a list of all public methods which have been protected from use as an action.
hide_action (line 571)
Accepts the names of one or more public methods which are protected from invocation as an action.
layout (line 191)
Accessor for this controller's layout name
logger (line 1012)
Return a logger instance for the class
model (line 1065)
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:
not_found (line 489)
Return a 404 not found message back.
on_exception (line 1025)
Handle an exception thrown in an action.
perform_action (line 455)
Perform the current action. This method is intended only for use by handle_request().
prepare_for_render (line 737)
Prepare template and layout for rendering.
protect_from_forgery (line 901)
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.
redirect_to (line 614)
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_event_listener (line 962)
Remove an event listener from this class.
rendered (line 212)
Accessor for this controller's rendered flag
render_action (line 631)
Render the template for the action
Options are:
render_error (line 660)
Render an error document
Options are:
render_to_string (line 644)
Render the template as a string.
require_https (line 865)
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.
require_post (line 882)
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.
set_action (line 182)
This method sets the controller's action
set_error (line 252)
Set the error flag for the controller
set_flash (line 262)
Set a flash message
set_layout (line 203)
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'.
set_rendered (line 221)
This method sets the controller's rendered flag
set_routing (line 230)
Set the routing instance currently in use
set_template_defaults (line 792)
Set various template variables if they have not been set explicitly.
template_cache_id (line 814)
Returns the current template cache ID, in case you want to vary the cached output based on some condition.
template_compile_id (line 824)
Returns the current template compile ID, in case this controller changes the template directory.
url_for (line 364)
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.
will_cache (line 536)
Returns true if the given action name will be cached
__get (line 1088)
Invoked when an attempt is made to retrieve the value of an undeclared instance variable
__isset (line 1100)
Invoked when an attempt is made to call isset or empty for an undeclared instance variable
__set (line 1076)
Invoked when an attempt is made to set an undeclared instance variable
__unset (line 1110)
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