PHPonTrax
[ class tree: PHPonTrax ] [ index: PHPonTrax ] [ all elements ]

Class: ActionController

Source Location: /vendor/trax/action_controller.php

Class Overview


Action controller


Variables

Methods


Child classes:

Controller for an application

Class Details

[line 47]
Action controller

The ActionController base class operates as follows:

  1. Accept a URL as input
  2. Translate the URL into a controller and action
  3. Create the indicated controller object (which is a subclass of ActionController) and call its action method
  4. Render the output of the action method
  5. Redirect to the next URL
For details see the class tutorial




[ Top ]


Class Variables

$action =

[line 66]

Name of the action method in the controller class

Set by recognize_route()




Tags:


Type:   string


[ Top ]

$action_called =  false

[line 221]



Tags:

access:  private
todo:  Document this attribute

Type:   mixed


[ Top ]

$action_params = array()

[line 91]

Parameters for the action routine

Set by recognize_route(), passed as arguments to the controller's action routine.




Tags:


Type:   string[]


[ Top ]

$added_path =  ''

[line 82]

Path to add to other filesystem paths

Set by recognize_route()




Tags:

usedby:  ActionController::set_paths()
access:  private

Type:   string


[ Top ]

$after_filter =  null

[line 231]



Tags:

access:  protected
todo:  Document this attribute

Type:   mixed


[ Top ]

$after_filters = array()

[line 211]

List of filters to execute after calling action method

Set by add_after_filters()




Tags:


Type:   string[]


[ Top ]

$application_controller_file =

[line 158]

Filesystem path to application.php file

Set by recognize_route()




Tags:


Type:   string


[ Top ]

$application_helper_file =

[line 166]

Filesystem path to application_helper.php file

Set by recognize_route()




Tags:

usedby:  ActionController::process_route()
access:  private

Type:   string


[ Top ]

$asset_host =  null

[line 281]



Tags:

access:  public
todo:  Document this attribute
todo:  FIXME: Not referenced in this class - is it used by subclasses? If so, for what?

Type:   string


[ Top ]

$before_filter =  null

[line 226]



Tags:

access:  protected
todo:  Document this attribute

Type:   mixed


[ Top ]

$before_filters = array()

[line 203]

List of filters to execute before calling action method

Set by add_before_filters()




Tags:


Type:   string[]


[ Top ]

$controller =

[line 58]

Name of the controller (without the _controller.php)

Set by recognize_route() by parsing the URL and the routes in routes.php. The value of this string is set before any attempt is made to find the file containing the controller.




Tags:


Type:   string


[ Top ]

$controllers_path =

[line 99]

Filesystem path to ../app/controllers/ directory

Set by recognize_route()




Tags:

usedby:  ActionController::set_paths()
usedby:  ActionController::recognize_route()
access:  private

Type:   string


[ Top ]

$controller_class =

[line 265]

Class name of the controller

Set by recognize_route(). Derived from contents of $controller.




Tags:


Type:   string


[ Top ]

$controller_file =

[line 240]

Filesystem path to the PHP program file for this controller

Set by recognize_route()




Tags:


Type:   string


[ Top ]

$controller_object =

[line 273]

Instance of the controller class

Set by process_route()




Tags:


Type:   object


[ Top ]

$helpers = array()

[line 195]

List of additional helper files for this controller object

Set by add_helper()




Tags:

usedby:  ActionController::add_helper()
usedby:  ActionController::process_route()
access:  private

Type:   string[]


[ Top ]

$helpers_base_path =

[line 115]

Filesystem path to ../app/helpers/ directory

Set by recognize_route()




Tags:

usedby:  ActionController::process_route()
access:  private

Type:   string


[ Top ]

$helpers_path =

[line 107]

Filesystem path to ../app/helpers/extras directory

Set by recognize_route(), set_paths()




Tags:

usedby:  ActionController::set_paths()
usedby:  ActionController::recognize_route()
access:  private

Type:   string


[ Top ]

$helper_file =

[line 149]

Filesystem path to the controllername_helper.php file

Set by recognize_route()




Tags:


Type:   string


[ Top ]

$id =

[line 74]

Value of :id parsed from URL then forced to lower case

Set by recognize_route()




Tags:

usedby:  ActionController::recognize_route()
access:  private

Type:   string


[ Top ]

$keep_flash =  false

[line 303]

Whether to keep flash message after displaying it



Tags:

usedby:  ActionController::process_route()
access:  public

Type:   boolean


[ Top ]

$layouts_base_path =

[line 131]

Filesystem path to ../app/views/layouts/ directory

Set by recognize_route()




Tags:

usedby:  ActionController::determine_layout()
access:  private

Type:   string


[ Top ]

$layouts_path =

[line 123]

Filesystem path to ../app/views/layouts/extras directory

Set by recognize_route(), set_paths()




Tags:


Type:   string


[ Top ]

$loaded =  false

[line 174]

URL recognized, paths resoved, controller file found

Set by recognize_route()




Tags:


Type:   boolean


[ Top ]

$render_layout =  true

[line 297]

Render controllers layout

Can be overridden in the child controller to false




Tags:

access:  public

Type:   boolean


[ Top ]

$render_performed =  false

[line 216]



Tags:

access:  private
todo:  Document this attribute

Type:   mixed


[ Top ]

$router_loaded =  false

[line 187]

Whether a Router object was loaded



Tags:

var:  
  • true => $router points to the Router object
  • false => no Router object exists
usedby:  ActionController::recognize_route()
usedby:  ActionController::load_router()
access:  private
todo:  FIXME: No declaration of $router so no place to hang its documentation.

Type:   boolean


[ Top ]

$url_path =

[line 141]

User's URL in components

Contains user's URL stripped of TRAX_URL_PREFIX and leading and trailing slashes, then exploded into an array on slash boundaries.




Tags:

usedby:  ActionController::set_paths()
usedby:  ActionController::recognize_route()
access:  private

Type:   string[]


[ Top ]

$views_file_extention =  TRAX_VIEWS_EXTENTION

[line 289]

File extension appended to view files

Set from a define in environment.php. Usually phtml




Tags:


Type:   string


[ Top ]

$views_path =

[line 256]

Filesystem path to the ../app/views/ directory

Set by recognize_route()




Tags:


Type:   string


[ Top ]

$view_file =

[line 248]

Filesystem path to the view file selected for this action

Set by process_route()




Tags:

usedby:  ActionController::process_route()
access:  public

Type:   string


[ Top ]



Class Methods


constructor __construct [line 309]

ActionController __construct( )

Build a Router object and load routes from config/route.php



Tags:



[ Top ]

method add_after_filter [line 860]

void add_after_filter( mixed $filter_function_name)

Append an after filter to the filter chain



Tags:



Parameters:

mixed   $filter_function_name   String with the name of one filter function, or array of strings with the names of several filter functions.

[ Top ]

method add_before_filter [line 822]

void add_before_filter( mixed $filter_function_name)

Append a before filter to the filter chain



Tags:



Parameters:

mixed   $filter_function_name   String with the name of one filter function, or array of strings with the names of several filter functions.

[ Top ]

method add_helper [line 882]

void add_helper( $helper_name $helper_name)

Add a helper to the list of helpers used by a controller object



Tags:



Parameters:

$helper_name   $helper_name   string Name of a helper to add to the list

[ Top ]

method determine_layout [line 1152]

mixed determine_layout( [mixed $full_path = true])

Select a layout file based on the controller object



Tags:

return:  Layout file or null if none
usedby:  ActionController::process_route()
todo:  FIXME: Should this method be private?
uses:  ActionController::$layouts_path
uses:  ActionController::$layouts_base_path
uses:  ActionController::$controller_object


[ Top ]

method execute_after_filters [line 841]

void execute_after_filters( )

Execute the after filters



Tags:



[ Top ]

method execute_before_filters [line 799]

void execute_before_filters( )

Execute the before filters



Tags:



[ Top ]

method load_router [line 372]

void load_router( )

Load routes from configuration file config/routes.php

Routes are loaded by requiring routes.php from the configuration directory. The file routes.php contains statements of the form "$router->connect(path,params);" where (path,params) describes the route being added by the statement. Route syntax is described in the Router class tutorial.




Tags:



[ Top ]

method process_route [line 566]


method process_with_exception [line 1258]

void process_with_exception( mixed &$exception)

Generate an HTML page describing an error



Tags:



[ Top ]

method raise [line 1251]

void raise( string $error_message, string $error_heading, [string $error_code = "404"])

Raise an ActionControllerError exception



Tags:

usedby:  ActionController::process_route()
throws:  ActionControllerError


Parameters:

string   $error_message   Error message
string   $error_heading   Error heading
string   $error_code   Error code

[ Top ]

method recognize_route [line 420]

boolean recognize_route( )

Convert URL to controller, action and id

Parse the URL in $_SERVER['REDIRECT_URL'] into elements. Compute filesystem paths to the various components used by the URL and store the paths in object private variables. Verify that the controller exists.




Tags:



[ Top ]

method redirect_to [line 1232]

void redirect_to( [mixed $options = null])

Redirect the browser to a specified target

Redirect the browser to the target specified in $options. This parameter can take one of three forms:

  • Array: The URL will be generated by calling url_for() with the options.
  • String starting with a protocol:// (like http://): Is passed straight through as the target for redirection.
  • String not containing a protocol: The current protocol and host is prepended to the string.
  • back: Back to the page that issued the request. Useful for forms that are triggered from multiple places. Short-hand for redirect_to(request.env["HTTP_REFERER"])

Examples:

  • redirect_to(array(":action" => "show", ":id" => 5))
  • redirect_to("http://www.rubyonrails.org")
  • redirect_to("/images/screenshot.jpg")
  • redirect_to("back")




Tags:

todo:  FIXME: Make header configurable


Parameters:

mixed   $options   array or string url

[ Top ]

method render [line 893]

void render( [mixed $options = array()], [mixed $locals = array()], [mixed $return_as_string = false])

Renders the content that will be returned to the browser as the response body.



[ Top ]

method render_action [line 983]

void render_action( mixed $action, [mixed $options = array()])

Action rendering is the most common form and the type used automatically by Action Controller when nothing else is specified. By default, actions are rendered within the current layout (if one exists).

  • Renders the template for the action "goal" within the current controller
render(array("action" => "goal"))

  • Renders the template for the action "short_goal" within the current controller,
  • but without the current active layout
render(array("action" => "short_goal", "layout" => false))

  • Renders the template for the action "long_goal" within the current controller,
  • but with a custom layout
render(array("action" => "long_goal", "layout" => "spectacular"))




[ Top ]

method render_file [line 1025]

void render_file( mixed $path, [mixed $use_full_path = false], [mixed $locals = array()])

File rendering works just like action rendering except that it takes a filesystem path.

By default, the path is assumed to be absolute, and the current layout is not applied.

  • Renders the template located at the absolute filesystem path
render(array("file" => "/path/to/some/template.phtml")) render(array("file" => "c:/path/to/some/template.phtml"))

  • Renders a template within the current layout
render(array("file" => "/path/to/some/template.rhtml", "layout" => true)) render(array("file" => "c:/path/to/some/template.rhtml", "layout" => true))

  • Renders a template relative to app/views
render(array("file" => "some/template", "use_full_path" => true))




[ Top ]

method render_partial [line 1095]

void render_partial( string $path, [string[] $options = array()])

Rendering partials

Partial rendering is most commonly used together with Ajax calls that only update one or a few elements on a page without reloading. Rendering of partials from the controller makes it possible to use the same partial template in both the full-page rendering (by calling it from within the template) and when sub-page updates happen (from the controller action responding to Ajax calls). By default, the current layout is not used.

  • render_partial("win");
    Renders the partial located at app/views/controller/_win.phtml
  • render_partial("win", array("locals" => array("name" => "david")));
    Renders the same partial but also makes a local variable available to it
  • render_partial("win", array("collection" => array(...)));
    Renders a collection of the same partial by making each element of the collection available through the local variable "win" as it builds the complete response
  • render_partial("win", array("collection" => $wins, "spacer_template" => "win_divider"));
    Renders the same collection of partials, but also renders the win_divider partial in between each win partial.




Parameters:

string   $path   Path to file containing partial view
string[]   $options   Options array

[ Top ]

method render_text [line 954]

void render_text( mixed $text, [mixed $options = array()])

Rendering of text is usually used for tests or for rendering prepared content.

By default, text rendering is not done within the active layout.

  • Renders the clear text "hello world"
render(array("text" => "hello world!"))

  • Renders the clear text "Explosion!"
render(array("text" => "Explosion!"))

  • Renders the clear text "Hi there!" within the current active layout (if one exists)
render(array("text" => "Explosion!", "layout" => true))

  • Renders the clear text "Hi there!" within the layout
  • placed in "app/views/layouts/special.phtml"
render(array("text" => "Explosion!", "layout" => "special"))




[ Top ]

method render_to_string [line 1005]

void render_to_string( [mixed $options = array()], [mixed $locals = array()])

Renders according to the same rules as render, but returns the result in a string instead of sending it as the response body to the browser.



[ Top ]

method set_paths [line 771]

void set_paths( )

Extend the search path for components

On entry, $url_path is set according to the browser's URL and $controllers_path has been set according to the configuration in config/environment.php . Examine the $controllers_path directory for files or directories that match any component of the URL. If one is found, add that component to all paths. Replace the contents of $url_path with the list of URL components that did NOT match any files or directories.




Tags:

uses:  ActionController::$url_path
todo:  FIXME: Creating a file or directory in app/controllers with the same name as a controller, action or other URL element will hijack the browser!
usedby:  ActionController::recognize_route()
uses:  ActionController::$views_path
uses:  ActionController::$layouts_path
uses:  ActionController::$controllers_path
uses:  ActionController::$helpers_path
uses:  ActionController::$added_path


[ Top ]

method __call [line 342]

void __call( mixed $method_name, mixed $parameters)



Tags:

todo:  Document this method Implement before_filter(), after_filter(), helper()


[ Top ]

method __set [line 321]

void __set( mixed $key, mixed $value)



Tags:



[ Top ]


Documentation generated on Thu, 04 May 2006 19:47:01 -0600 by phpDocumentor 1.3.0RC4