tina_mvc/base_classes/tina_mvc_base_classes.php
- Author
- Francis Crossen
- Package
- Tina-MVC
- Subpackage
- Core
Constants
\TINA_MVC\tina_mvc_controller_class
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.
- Children
- \admin_pages_controller
- \tina_mvc_child_page_controller
- \index_controller
- \registration_controller
- \page_test_1_controller
- \html_table_controller
- \page_test_3_controller
- \page_test_2_controller
- \test_form_2_controller
- \using_views_controller
- \test_form_controller
- \hello_world_controller
- \index_controller
- $request
- array
extracted from $_GET - /controller/action/some/data
boolean
Properties
array $request
the Tina MVC request array( 'tina_page', 'controller', 'method', 'data1', 'data2', ... )
- Type
- array
string $shortcode_content = ''
if called from a non self-closing shortcode, the content
''
Details- Type
- string
- See
- \TINA_MVC\tina_mvc_shortcode_func()
object $template_vars
View data for passing to a template. Contains 2 objects, one for escaped data and one for non escaped data
- Type
- object
- See
- \TINA_MVC\$this->add_var()
- See
- \TINA_MVC\$this->add_var_e()
Methods
__construct(array $request = array(), string $called_from = 'PAGE_FILTER') : void
Sets the Tina MVC request.
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) : boolean
Add a variable to $this->template_vars
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) : boolean
Add an escaped variable to $this->view_data
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() : void
Calls controller functions based on the Tina MVC request (page/controller/function/data1/data2/.
..)
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() : string
Gets the Wordpress Tina MVC page content
Used by tina_mvc_controller_class
Type | Description |
---|---|
string |
get_post_title() : string
Gets the Wordpress Tina MVC page title
Used by tina_mvc_controller_class
Type | Description |
---|---|
string |
include_model(string $f, string $m) : mixed
Includes a model
The 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() : void
An empty function to prevent errors when the dispatcher function attempts to call index().
This function would normally be redefined by your own controller
load_model(string $model = '', string $custom_folder = FALSE) : object
Locates a Tina MVC model file and return an instance of the model class
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) : string
Includes/Parses a HTML file and return as a string
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()) : boolean
Grabs an email message template and merges it with any variables you pass.
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 |
- Todo
- sending attachments
parse_view_file(string $f, mixed $V, boolean $add_html_comments = TRUE) : mixed
Includes and parses a view file or an email 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) : void
Sets the Tina MVC page content from your application
Name | Type | Description |
---|---|---|
$str | string |
set_post_title(string $str) : void
Sets the Tina MVC page title from your application
Name | Type | Description |
---|---|---|
$str | string |
\TINA_MVC\tina_mvc_model_class
Derive your models from this class. So far the only thing we do is to globalise the $wpdb variable and assign it as a class variable.
Properties
Methods
\TINA_MVC\tina_mvc_page_class
Checks the controller request and permissions.
If permissions are not met, and the $tina_mvc_app_settings->login_redirect is in use redirects to a custom login page.
Else $tina_mvc_app_settings->no_permission_behaviour is checked to see what way to handle the condition.
If permissions are met, locates and includes the controller and instantiates it. The $tina_mvc_request is passed to the controller class. The controller set the post title and content. The calling code can later retrive these variables.
- $request
- string
/tina_mvc-page/controller/method/and/other/data/to/pass
- $role_to_view
- mixed
comma separated string or string or array of roles.
- $capability_to_view
- mixed
FALSE allows general access, OR comma separated string or string or array of capabilities. Overrides the role check
- $called_from
- mixed
'PAGE_FILTER', 'WIDGET', 'SHORTCODE' or 'CALL_CONTROLLLER_FUNC'
- $custom_folder
- string
an overriding location to look for the controller in
- $shortcode_content
- string
the content encapsulated by the tina_mvc shortcode (if any)
Properties
mixed $CONTROLLER
Use setters and getters.
- Type
- mixed
mixed $MODEL
Use setters and getters.
- Type
- mixed
mixed $allow_http_redirects
Use setters and getters.
- Type
- mixed
mixed $called_from
Use setters and getters.
- Type
- mixed
mixed $find_app_file_error
Use setters and getters.
- Type
- mixed
mixed $is_404
Use setters and getters.
- Type
- mixed
mixed $raw_request
Use setters and getters.
- Type
- mixed
mixed $request
Use setters and getters.
- Type
- mixed
mixed $tina_mvc_page
Use setters and getters.
- Type
- mixed
Methods
__construct(String $raw_request = '', Boolean $role_to_view = NULL, Boolean $capability_to_view = NULL, String $called_from = 'PAGE_FILTER', Boolean $custom_folder = FALSE, Object $shortcode_content = FALSE) : void
Checks permissions and instantiates the controller.
Sets the page title and content.
Name | Type | Description |
---|---|---|
$raw_request | String | a path /tina_mvc-page/controller/method/and/other/data/to/pass |
$role_to_view | Boolean | FALSE allows all to view; '' must be loogged in to view; array or comma separated list of roles to view |
$capability_to_view | Boolean | as for $role_to_view. Overrides the $role_to_view |
$called_from | String | 'PAGE_FILTER', 'WIDGET', 'SHORTCODE' or 'CALL_CONTROLLLER_FUNC' |
$custom_folder | Boolean | custom location for the controller |
$shortcode_content | Object |
do_login() : Boolean
Displays and processes a login form
Used if a user is not authorised to view. Forces a login
Type | Description |
---|---|
Boolean | TRUE if user passed authentication |
get_instance_of(string $folder = '', string $shortcode_content) : boolean
An autoloader
Name | Type | Description |
---|---|---|
$folder | string | |
$shortcode_content | string |
Type | Description |
---|---|
boolean | TRUE on success. FALSE only if called from a shortcode. Other failures trigger an error. |
- Uses
- \TINA_MVC\$this->include_controller()
include_controller(Boolean $controller_file = FALSE, String $controller_name = '') : object
Include a controller and set up the Tina MVC request
Name | Type | Description |
---|---|---|
$controller_file | Boolean | Full path and filename of controller to include |
$controller_name | String | the class to instantiate |
Type | Description |
---|---|
object | Tina MVC controller |
merge_permissions(mixed $p1 = FALSE, mixed $p2 = FALSE) : mixed
Merge roles and capabilities passed to the Tina MVC controller
Roles and capabalities may be specified as a string, a comma seperated list or an array. This function checks the format of the arguments and merges them into an array.
Name | Type | Description |
---|---|---|
$p1 | mixed | |
$p2 | mixed |
Type | Description |
---|---|
mixed |
permissions_to_array(mixed $p = FALSE) : mixed
Converts a Tina MVC role or permission entry to an array or FALSE
Name | Type | Description |
---|---|---|
$p | mixed |
Type | Description |
---|---|
mixed |