Back to top

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
documentation:rack:reference:views [2019/05/10 17:55] – Document ModelView->run_csv() behaviour Martijn Luinstradocumentation:rack:reference:views [2023/08/31 23:22] (current) Martijn Luinstra
Line 4: Line 4:
  
 ==== Functions ==== ==== Functions ====
-  * <php>abstract run()</php> This function should implement the logic of the view.  +  * ''%%abstract run()%%'' This function should implement the logic of the view.  
-  * <php>protected redirect($url, $status_code=302)</php> This function performs a redirect to the provided url.+  * ''%%protected redirect($url, $status_code=302)%%'' This function performs a redirect to the provided url.
  
  
 ===== TemplateView ===== ===== TemplateView =====
  
-<php>TemplateView</php> extends <php>View</php>.+''%%TemplateView%%'' extends ''%%View%%''.
  
 ==== Pipelines ==== ==== Pipelines ====
  
 === Running the view === === Running the view ===
-  - <php>run()</php> +  - ''%%run()%%'' 
-  - if exception: <php>run_exception($exception)</php>:+  - if exception: ''%%run_exception($exception)%%'':
     - renders error template     - renders error template
-  - <php>run_form($form)</php> +  - ''%%run_form($form)%%'' 
-  - else: <php>run_page()</php>+  - else: ''%%run_page()%%''
     - renders page template     - renders page template
  
 === Resolving a template name === === Resolving a template name ===
-  - If <php>$this->template</php> is set, return that. +  - If ''%%$this->template%%'' is set, return that. 
-  - If <php>$view_name</php> is set, return <php>'[base_name]_[view_name].phtml'</php>+  - If ''%%$view_name%%'' is set, return ''%%'[base_name]_[view_name].phtml'%%''
-  - Else return <php>'[base_name].phtml'</php>.+  - Else return ''%%'[base_name].phtml'%%''.
  
-Where <php>$base_name</php> defaults to <php>'template_[page_id]'</php> but can be overriden by setting the <php>$template_base_name</php> property.+Where ''%%$base_name%%'' defaults to ''%%'template_[page_id]'%%'' but can be overriden by setting the ''%%$template_base_name%%'' property.
  
 ==== Properties ==== ==== Properties ====
  
-  * <php>protected $page_id</php> String used to identify the template name and the page title +  * ''%%protected $page_id%%'' String used to identify the template name and the page title 
-  * <php>protected $template</php> Contains the view's form, but obsolete if you override <php>get_form()</php>+  * ''%%protected $template%%'' Contains the view's form, but obsolete if you override ''%%get_form()%%''
-  * <php>protected $template_base_name</php> Contains the view's success_url, but obsolete if you override <php>get_succes_url()</php> or <php>run_form_valid()</php>+  * ''%%protected $template_base_name%%'' Contains the view's success_url, but obsolete if you override ''%%get_succes_url()%%'' or ''%%run_form_valid()%%''
-  * <php>protected $title</php> Contains a human readable page title.+  * ''%%protected $title%%'' Contains a human readable page title.
  
 ==== Functions ==== ==== Functions ====
  
-<php>TemplateView</php> inherits all functions from <php>View</php>. It implements <php>run()</php>.+''%%TemplateView%%'' inherits all functions from ''%%View%%''. It implements ''%%run()%%''.
  
-  * <php>__construct($page_id, $title='')</php> +  * ''%%__construct($page_id, $title='')%%'' 
-  * <php>run()</php> 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 <php>run_page()</php>+  * ''%%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()%%''
-  * <php>protected run_page()</php> +  * ''%%protected run_page()%%'' 
-  * <php>protected run_exception($e)</php> +  * ''%%protected run_exception($e)%%'' 
-  * <php>protected render_template($template, array $context=[])</php> Renders a template with context. Merges in the default context. +  * ''%%protected render_template($template, array $context=[])%%'' Renders a template with context. Merges in the default context. 
-  * <php>protected function get_default_context()</php> Returns the default context. The default implementation returns the view'<php>$title</php> and <php>$page_id</php>+  * ''%%protected function get_default_context()%%'' Returns the default context. The default implementation returns the view'''%%$title%%'' and ''%%$page_id%%''
-  * <php>protected function get_template($view_name='')</php>+  * ''%%protected function get_template($view_name='')%%''
  
  
 ===== Abstract: FormView ===== ===== Abstract: FormView =====
  
-<php>FormView</php> extends <php>TemplateView</php>.+''%%FormView%%'' extends ''%%TemplateView%%''.
  
 ==== Pipelines ==== ==== Pipelines ====
  
 === Running the view === === Running the view ===
-  - <php>run()</php> +  - ''%%run()%%'' 
-  - <php>run_page()</php> +  - ''%%run_page()%%'' 
-  - <php>run_form($form)</php> +  - ''%%run_form($form)%%'' 
-  - if form validates: <php>run_form_valid($form)</php> +  - if form validates: ''%%run_form_valid($form)%%'' 
-    - <php>process_form_data($data)</php>+    - ''%%process_form_data($data)%%''
     - redirects to succes_url     - redirects to succes_url
-  - else: <php>run_form_invalid($form)</php>+  - else: ''%%run_form_invalid($form)%%''
     - renders form     - renders form
  
 ==== Properties ==== ==== Properties ====
  
-<php>FormView</php> inherits all properties from <php>TemplateView</php>.+''%%FormView%%'' inherits all properties from ''%%TemplateView%%''.
  
-  * <php>protected $form</php> Contains the view's form, but obsolete if you override <php>get_form()</php>+  * ''%%protected $form%%'' Contains the view's form, but obsolete if you override ''%%get_form()%%''
-  * <php>protected $success_url</php> Contains the view's success_url, but obsolete if you override <php>get_succes_url()</php> or <php>run_form_valid()</php>.+  * ''%%protected $success_url%%'' Contains the view's success_url, but obsolete if you override ''%%get_succes_url()%%'' or ''%%run_form_valid()%%''.
  
 ==== Functions ==== ==== Functions ====
  
-<php>FormView</php> inherits all functions from <php>TemplateView</php>. It implements <php>run_page()</php>.+''%%FormView%%'' inherits all functions from ''%%TemplateView%%''. It implements ''%%run_page()%%''.
  
-  * <php>protected run_form($form)</php> It is not recommended to override this function if you want to customize form handling. Override <php>form_valid()</php> and <php>form_invalid()</php> instead. +  * ''%%protected 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. 
-  * <php>protected form_valid($form)</php> +  * ''%%protected form_valid($form)%%'' 
-  * <php>protected form_invalid($form)</php> +  * ''%%protected form_invalid($form)%%'' 
-  * <php>abstract protected process_form_data($data)</php> This function should implement the logic used to process the form data. The <php>$data</php> variable is an associated array containing //field_name// => //value// pairs. +  * ''%%abstract protected 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_name// => //value// pairs. 
-  * <php>protected get_form()</php> +  * ''%%protected get_form()%%'' 
-  * <php>protected get_success_url()</php>+  * ''%%protected get_success_url()%%''
  
  
Line 87: Line 87:
 ===== ModelView ===== ===== ModelView =====
  
-<php>ModelView</php> extends <php>FormView</php>.+''%%ModelView%%'' extends ''%%FormView%%''.
  
 ==== Pipelines ==== ==== Pipelines ====
  
 === Running the view === === Running the view ===
-  - <php>run()</php> +  - ''%%run()%%'' 
-  - <php>run_page()</php> +  - ''%%run_page()%%'' 
-  - if view = create: <php>run_create()</php> +  - if view = create: ''%%run_create()%%'' 
-    - <php>get_form()</php> +    - ''%%get_form()%%'' 
-    - <php>run_form($form)</php> according to FormView pipeline +    - ''%%run_form($form)%%'' according to FormView pipeline 
-  - if view = read: <php>run_read()</php> +  - if view = read: ''%%run_read()%%'' 
-    - <php>get_object()</php>+    - ''%%get_object()%%''
     - renders template for view = read with context variable 'object'     - renders template for view = read with context variable 'object'
-  - if view = update: <php>run_update()</php> +  - if view = update: ''%%run_update()%%'' 
-    - <php>get_form()</php> +    - ''%%get_form()%%'' 
-    - populate form with <php>get_object()</php> +    - populate form with ''%%get_object()%%'' 
-    - <php>run_form($form)</php> according to FormView pipeline +    - ''%%run_form($form)%%'' according to FormView pipeline 
-  - if view = delete: <php>run_delete()</php>+  - if view = delete: ''%%run_delete()%%''
     - if request method = POST     - if request method = POST
       - delete object       - delete object
Line 110: Line 110:
     - else     - else
       - renders template for view = delete with context variable 'object'       - renders template for view = delete with context variable 'object'
-  - if view = list: <php>run_list()</php>+  - if view = list: ''%%run_list()%%''
     - renders template for view = list with context variable 'objects'     - renders template for view = list with context variable 'objects'
  
 ==== Properties ==== ==== Properties ====
  
-<php>ModelView</php> inherits all properties from <php>FormView</php>.+''%%ModelView%%'' inherits all properties from ''%%FormView%%''.
  
-  * <php>protected $views</php> List of implemented views. Defaults to <php>['create', 'read', 'update', 'delete', 'list']</php>. Additionally a view for export to CSV (<php>'csv'</php>) has been implemented, but is disabled by default. +  * ''%%protected $views%%'' List of implemented views. Defaults to ''%%['create', 'read', 'update', 'delete', 'list']%%''. Additionally a view for export to CSV (''%%'csv'%%'') has been implemented, but is disabled by default. 
-  * <php>protected $default_view</php> The name of the view to run if the URL parameter <php>view</php> is not provided. Defaults to <php>"list"</php>+  * ''%%protected $default_view%%'' The name of the view to run if the URL parameter ''%%view%%'' is not provided. Defaults to ''%%"list"%%''
-  * <php>protected $model</php> Contains the view's model object, but obsolete if you override <php>get_model()</php>.+  * ''%%protected $model%%'' Contains the view's model object, but obsolete if you override ''%%get_model()%%''.
  
 ==== Functions ==== ==== Functions ====
  
-<php>ModelView</php> inherits all functions from <php>FormView</php>. It implements <php>process_form_data()</php> and overrides <php>__construct()</php><php>run_page()</php><php>get_success_url()</php> and <php>get_template()</php>.+''%%ModelView%%'' inherits all functions from ''%%FormView%%''. It implements ''%%process_form_data()%%'' and overrides ''%%__construct()%%''''%%run_page()%%''''%%get_success_url()%%'' and ''%%get_template()%%''.
  
-  * <php>public __construct($page_id, $title='', $model=null, $form=null)</php> +  * ''%%public __construct($page_id, $title='', $model=null, $form=null)%%'' 
-  * <php>protected run_page()</php> It is not recommended to override this function unless you want to create additional views. Override <php>run_create()</php><php>run_read()</php><php>run_update()</php><php>run_delete()</php><php>run_list()</php> and <php>run_csv()</php> instead. +  * ''%%protected run_page()%%'' It is not recommended to override this function unless you want to create additional views. Override ''%%run_create()%%''''%%run_read()%%''''%%run_update()%%''''%%run_delete()%%''''%%run_list()%%'' and ''%%run_csv()%%'' instead. 
-  * <php>protected run_create()</php> +  * ''%%protected run_create()%%'' 
-  * <php>protected run_read()</php> +  * ''%%protected run_read()%%'' 
-  * <php>protected run_update()</php> +  * ''%%protected run_update()%%'' 
-  * <php>protected run_delete()</php> +  * ''%%protected run_delete()%%'' 
-  * <php>protected run_list()</php> +  * ''%%protected run_list()%%'' 
-  * <php>protected run_csv()</php> Disabled by default. Enable by overriding <php>$views</php> (add <php>'csv'</php>). +  * ''%%protected run_csv()%%'' Disabled by default. Enable by overriding ''%%$views%%'' (add ''%%'csv'%%''). 
-  * <php>protected get_csv_data()</php> Provides dataset for <php>run_csv()</php> as associative array. +  * ''%%protected get_csv_data()%%'' Provides dataset for ''%%run_csv()%%'' as associative array. 
-  * <php>protected process_form_data($data)</php> Creates or updates object in database. +  * ''%%protected process_form_data($data)%%'' Creates or updates object in database. 
-  * <php>protected get_model()</php> +  * ''%%protected get_model()%%'' 
-  * <php>protected get_object()</php> +  * ''%%protected get_object()%%'' 
-  * <php>protected get_success_url()</php> Overridden to redirect to the default view. +  * ''%%protected get_success_url()%%'' Overridden to redirect to the default view. 
-  * <php>protected get_template($view_name='')</php> Overridden to render the template for the active view if <php>$view_name</php> is not provided.+  * ''%%protected get_template($view_name='')%%'' Overridden to render the template for the active view if ''%%$view_name%%'' is not provided.
  

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