Back to top

Differences

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

Link to this comparison view

Next revisionBoth sides next revision
documentation:rack:reference:views [2018/05/25 18:15] – created Martijn Luinstradocumentation:rack:reference:views [2018/05/25 18:56] Martijn Luinstra
Line 38: Line 38:
 ==== Functions ==== ==== Functions ====
  
-TemplateView inherits all functions from ''View''. It implements ''run()''.+''TemplateView'' inherits all functions from ''View''. It implements ''run()''.
  
-  * **''public function __construct($page_id, $title="")''**+  * **''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()''.   * **''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_page()''**
Line 51: Line 51:
 ===== Abstract: FormView ===== ===== Abstract: FormView =====
  
-''FormView'' extends ''TemplateView'' .+''FormView'' extends ''TemplateView''.
  
 ==== Pipelines ==== ==== Pipelines ====
Line 67: Line 67:
 ==== Properties ==== ==== Properties ====
  
-FormView inherits all properties from ''TemplateView''.+''FormView'' inherits all properties from ''TemplateView''.
  
   * **''protected $form''** Contains the view's form, but obsolete if you override ''get_form()''.   * **''protected $form''** Contains the view's form, but obsolete if you override ''get_form()''.
Line 74: Line 74:
 ==== Functions ==== ==== Functions ====
  
-FormView inherits all functions from ''TemplateView''. It implements ''run_page()''.+''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 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.
Line 82: Line 82:
   * **''protected function get_form()''**   * **''protected function get_form()''**
   * **''protected function get_success_url()''**   * **''protected function get_success_url()''**
 +
 +
 +
 +===== ModelView =====
 +
 +''ModelView'' extends ''FormView''.
 +
 +==== Pipelines ====
 +
 +=== Running the view ===
 +  - ''run()''
 +  - ''run_page()''
 +  - if view = create: ''run_create()''
 +    - ''get_form()''
 +    - ''run_form($form)'' according to FormView pipeline
 +  - if view = read: ''run_read()''
 +    - ''get_object()''
 +    - renders template for view = read with context variable 'object'
 +  - if view = update: ''run_update()''
 +    - ''get_form()''
 +    - populate form with ''get_object()''
 +    - ''run_form($form)'' according to FormView pipeline
 +  - if view = delete: ''run_delete()''
 +    - if request method = POST
 +      - delete object
 +      - redirect to success url
 +    - else
 +      - renders template for view = delete with context variable 'object'
 +  - if view = list: ''run_list()''
 +    - renders template for view = list with context variable 'objects'
 +
 +==== Properties ====
 +
 +''ModelView'' inherits all properties from ''FormView''.
 +
 +  * **''protected $views''** List of implemented views. Defaults to ''['create', 'read', 'update', 'delete', 'list']''.
 +  * **''protected $default_view''** The name of the view to run if the URL parameter ''view'' is not provided. Defaults to ''"list"''.
 +  * **''protected $model''** Contains the view's model object, but obsolete if you override ''get_model()''.
 +
 +==== Functions ====
 +
 +''ModelView'' inherits all functions from ''FormView''. It implements ''process_form_data()'' and overrides ''__construct()'', ''run_page()'', ''get_success_url()'' and ''get_template()''.
 +
 +  * **''public function _construct($page_id, $title="", $model=null, $form=null)''**
 +  * **''protected function 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()'' and ''run_list()'' instead.
 +  * **''run_create()''**
 +  * **''run_read()''**
 +  * **''run_update()''**
 +  * **''run_delete()''**
 +  * **''run_list()''**
 +  * **''protected function process_form_data($data)''** Creates or updates object in database.
 +  * **''protected function get_model()''**
 +  * **''protected function get_object()''**
 +  * **''protected function get_success_url()''** Overridden to redirect to the default view.
 +  * **''protected function get_template($view_name="")''** Overridden to render the template for the active view if ''$view_name'' is not provided.
  

documentation/rack/reference/views.txt · Last modified: 2023/08/31 23:22 by Martijn Luinstra