samples/09_form_helper_advanced/test_form_2_controller.php
- Author
- Francis Crossen
- Package
- Tina-MVC
- Subpackage
- Samples
\test_form_2_controller
Setter and getter for the Wordpress $the_post_title, $the_post_content variables. Loads HTML view files (templates), merging them with PHP variables
If you want to access the Tina MVC request from the constructor of your derived class, you must call the parent constructor. Otherwise use the dispatcher functionality and place your code the class methods.
- Parent(s)
- \TINA_MVC\tina_mvc_controller_class
Properties

array $capability_to_viewoverrides the defaults from app_settings.php
- Type
- array
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$capability_to_view

string $raw_request'tina_page/controller/method/data1/data2'
- Type
- string
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$raw_request

array $requestthe Tina MVC request array( 'tina_page', 'controller', 'method', 'data1', 'data2', ... )
- Type
- array
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$request

array $role_to_viewoverrides the defaults from app_settings.php
- Type
- array
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$role_to_view

string $shortcode_content = ''if called from a non self-closing shortcode, the content
''Details- Type
- string
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$shortcode_content
- See
- \TINA_MVC\tina_mvc_shortcode_func()

object $template_varsView data for passing to a template. Contains 2 objects, one for escaped data and one for non escaped data
- Type
- object
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$template_vars
- See
- \TINA_MVC\$this->add_var()
- See
- \TINA_MVC\$this->add_var_e()

string $the_post_contentthe controllers output
- Type
- string
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$the_post_content

string $the_post_titlethe controllers output
- Type
- string
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$the_post_title

array $tina_mvc_page- Type
- array
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$tina_mvc_page

boolean $use_dispatcher = TRUEwhether to use the dispatcher method after creating an instance of the derived class.
TRUEDetails- Type
- boolean
- Inherited_from
- \TINA_MVC\tina_mvc_controller_class::$$use_dispatcher
- See
- \TINA_MVC\$this->dispatcher()
Methods

__construct(array $request = array(), string $called_from = 'PAGE_FILTER') : voidSets the Tina MVC request.
Inherited from: \TINA_MVC\tina_mvc_controller_class::__construct()If you are using the dispatcher functionality then you do not need to call this constructor from yoru child classes. The Tina MVC request is set by the base controller before calling the dispatch() function.
| Name | Type | Description |
|---|---|---|
| $request | array | the Tina MVC request |
| $called_from | string | 'PAGE_FILTER', 'WIDGET', 'SHORTCODE' or 'CALL_CONTROLLLER_FUNC' |

add_var(string $key = NULL, mixed $v = NULL, boolean $esc = FALSE) : booleanAdd a variable to $this->template_vars
Inherited from: \TINA_MVC\tina_mvc_controller_class::add_var()Allows you to drop your template variables into an object for retrieval by $this->load_vew()
The key is added as a property of (object) $this->template_vars
| Name | Type | Description |
|---|---|---|
| $key | string | the object property name to use when adding data |
| $v | mixed | variable to add |
| $esc | boolean | whether to escape data or not |
| Type | Description |
|---|---|
| boolean |
- See
- \TINA_MVC\$this->template_vars
- See
- \TINA_MVC\$this->add_var_e()
- See
- \TINA_MVC\$this->load_view()

add_var_e(string $key = NULL, mixed $v = NULL) : booleanAdd an escaped variable to $this->view_data
Inherited from: \TINA_MVC\tina_mvc_controller_class::add_var_e()Any variables added using this will be escaped. Allows you to drop your template variables into an object for retrieval by $this->load_vew()
| Name | Type | Description |
|---|---|---|
| $key | string | the object property name to use when adding data |
| $v | mixed | variable to add |
| Type | Description |
|---|---|
| boolean |
- See
- \TINA_MVC\$this->view_Data
- See
- \TINA_MVC\$this->add_var()
- See
- \TINA_MVC\$this->load_view()

dispatch() : voidCalls controller functions based on the Tina MVC request (page/controller/function/data1/data2/.
Inherited from: \TINA_MVC\tina_mvc_controller_class::dispatch()..)
If there is no function call in the Tina MVC request, $this->index() is called. Otherwise looks for a class method based on the function part of the request. This allows you to name your class methods according to your actions. e.g. page/controller/my-action will be mapped on to $this->my_action(). Default action is always $this->index()
The dispatcher is used by default.
Make any methods that you do not want called by the dispatcher method 'private' for security and name them with a leading underscore to prevent the dispatcher from trying to load them. E.g. '_my_method'

get_post_content() : stringGets the Wordpress Tina MVC page content
Inherited from: \TINA_MVC\tina_mvc_controller_class::get_post_content()Used by tina_mvc_controller_class
| Type | Description |
|---|---|
| string |

get_post_title() : stringGets the Wordpress Tina MVC page title
Inherited from: \TINA_MVC\tina_mvc_controller_class::get_post_title()Used by tina_mvc_controller_class
| Type | Description |
|---|---|
| string |

include_model(string $f, string $m) : mixedThe same search order is used as for controllers
| Name | Type | Description |
|---|---|---|
| $f | string | the full path and filname |
| $m | string | the model name |
| Type | Description |
|---|---|
| mixed | the model object or FALSE |

index() : voidThe default controller
This function would normally be redefined by your own controller

load_model(string $model = '', string $custom_folder = FALSE) : objectLocates a Tina MVC model file and return an instance of the model class
Inherited from: \TINA_MVC\tina_mvc_controller_class::load_model()Looks for a file in the same order as for controllers and view files. Model files are named {$model}_model.php and define a class called {$model}
| Name | Type | Description |
|---|---|---|
| $model | string | the name of the model file (without '_model.php') |
| $custom_folder | string | path to load the model from |
| Type | Description |
|---|---|
| object | an instance of the model class |

load_view(string $view = false, mixed $V = NULL, string $custom_folder = FALSE) : stringIncludes/Parses a HTML file and return as a string
Inherited from: \TINA_MVC\tina_mvc_controller_class::load_view()Looks for a file in the same folder as the controller named {$view}_view.php and includes it. Any variables passed in $V are extracted into the global scope of the HTML view file. This allows the use of
and
= $somearray[0] ?>
template constructs.
In fact we can use any
.. do something ..
just like in normal PHP mixed HTML/PHP templating. {$view}_view.php is intended to be a HTML file
If $view is FALSE and $V is string, the string data is used as the parsed view file. i.e. without requiring a view file.
Alternatively you can assign template data to $this->template_vars using $this->add_var() and $this->add_var_e(). If data is in $this->template_vars it will be used in preference to data passed to this function.
You should use
if( !defined('TINA_MVC_LOAD_VIEW') ) die;
or something similar to avoid users being able to call the template directly.
| Name | Type | Description |
|---|---|---|
| $view | string | the name of the view file (without '_view.php') |
| $V | mixed | variable (usually array or object) passed to the included file for parsing by the template |
| $custom_folder | string | an overriding location to load the view from (relative to the Tina MVC plugin folder) |
| Type | Description |
|---|---|
| string | the parsed view file (usually HTML) |
- See
- \TINA_MVC\$this->view_data

mail(mixed $to = FALSE, mixed $cc = FALSE, mixed $bcc = FALSE, string $subject, string $message_template = FALSE, array $message_variables = array()) : booleanGrabs an email message template and merges it with any variables you pass.
Inherited from: \TINA_MVC\tina_mvc_controller_class::mail()Use this for any emails you want to send through Tina MVC. Templates are like normal Tina MVC view files except they are named *_email.php.
The templates are stored in the user or Tina MVC 'pages', 'shortcodes' and 'widgets' folders (just like controllers, views and models).
Variables are extract() ed into the local scope of the message template. $to, $cc, $bcc and $subject will also be added to that scope. Beware: this will overwrite variables of the same name passed through $message_variables.
| Name | Type | Description |
|---|---|---|
| $to | mixed | The recipients address (array or string) |
| $cc | mixed | |
| $bcc | mixed | |
| $subject | string | |
| $message_template | string | Template to use (without the '_email.php') |
| $message_variables | array | Data to be merged into the message (usually array or object ) |
| Type | Description |
|---|---|
| boolean |

parse_view_file(string $f, mixed $V, boolean $add_html_comments = TRUE) : mixedIncludes and parses a view file or an email file
Inherited from: \TINA_MVC\tina_mvc_controller_class::parse_view_file()| Name | Type | Description |
|---|---|---|
| $f | string | full path and filename to file |
| $V | mixed | the view data |
| $add_html_comments | boolean | Add HTML comments at the start and end of the view file |
| Type | Description |
|---|---|
| mixed | FALSE or the parsed view file |

set_post_content(string $str) : voidSets the Tina MVC page content from your application
Inherited from: \TINA_MVC\tina_mvc_controller_class::set_post_content()| Name | Type | Description |
|---|---|---|
| $str | string |

set_post_title(string $str) : voidSets the Tina MVC page title from your application
Inherited from: \TINA_MVC\tina_mvc_controller_class::set_post_title()| Name | Type | Description |
|---|---|---|
| $str | string |

set_request(string $request = array(), string $raw_request = '') : voidSets the Tina MVC raw_request (handy to have if you need the original uri)
Inherited from: \TINA_MVC\tina_mvc_controller_class::set_request()| Name | Type | Description |
|---|---|---|
| $request | string | |
| $raw_request | string |