Back to top

This is an old revision of the document!


Views

Abstract: View

Functions

  • abstract public function run() This function should implement the logic of the view.
  • protected function redirect($url, $status_code=302) This function performs a redirect to the provided url.

TemplateView

TemplateView extends View.

Pipelines

Running the view

  1. run()
  2. if exception: run_exception($exception):
    1. renders error template
  3. run_form($form)
  4. else: run_page()
    1. renders page template

Resolving a template name

  1. If $this→template is set, return that.
  2. If $view_name is set, return “[$base_name]_[view_name].phtml”.
  3. Else return “[$base_name].phtml”.

Where $base_name defaults to “template_[$this→page_id]” but can be overriden by setting the $template_base_name property.

Properties

  • protected $page_id String used to identify the template name and the page title
  • protected $template Contains the view's form, but obsolete if you override get_form().
  • protected $template_base_name Contains the view's success_url, but obsolete if you override get_succes_url() or run_form_valid().
  • protected $title Contains a human readable page title.

Functions

TemplateView inherits all functions from View. It implements run().

  • public function __construct($page_id, $title=“”)
  • public function run() This function runs the logic of the view. It should not be overridden, as it makes sure exceptions are correctly rendered. If you want to customize how views are executed, you should override run_page().
  • protected function run_page()
  • protected function run_exception($e)
  • protected function render_template($template, array $context=[]) Renders a template with context. Merges in the default context.
  • protected function get_default_context() Returns the default context. The default implementation returns the view's $title and $page_id.
  • protected function get_template($view_name=“”)

Abstract: FormView

FormView extends TemplateView .

Pipelines

Running the view

  1. run()
  2. run_page()
  3. run_form($form)
  4. if form validates: run_form_valid($form)
    1. process_form_data($data)
    2. redirects to succes_url
  5. else: run_form_invalid($form)
    1. renders form

Properties

FormView inherits all properties from TemplateView.

  • protected $form Contains the view's form, but obsolete if you override get_form().
  • protected $success_url Contains the view's success_url, but obsolete if you override get_succes_url() or run_form_valid().

Functions

FormView inherits all functions from TemplateView. It implements run_page().

  • protected function run_form($form) It is not recommended to override this function if you want to customize form handling. Override form_valid() and form_invalid instead.
  • protected function form_valid($form)
  • protected function form_invalid($form)
  • abstract protected function process_form_data($data) This function should implement the logic used to process the form data. The $data variable is an associated array containing field_namevalue pairs.
  • protected function get_form()
  • protected function get_success_url()

documentation/rack/reference/views.1527264937.txt.gz · Last modified: 2022/04/03 16:00 (external edit)