tina_mvc/base_classes/tina_mvc_base_classes.php

Show: PublicProtectedPrivateinherited
Table of Contents
The base page, model, view and controller classes
Author
Francis Crossen  
Package
Tina-MVC  
Subpackage
Core  

Constants

>VConstant  TINA_MVC_LOAD_VIEW = true

\TINA_MVC\tina_mvc_controller_class

Package: Tina-MVC\Core
The 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

>VPropertypublicarray $capability_to_view

overrides the defaults from app_settings.php

Details
Type
array
>VPropertyprotectedstring $raw_request

'tina_page/controller/method/data1/data2'

Details
Type
string
>VPropertyprotectedarray $request

the Tina MVC request array( 'tina_page', 'controller', 'method', 'data1', 'data2', ... )

Details
Type
array
>VPropertypublicarray $role_to_view

overrides the defaults from app_settings.php

Details
Type
array
>VPropertypublicstring $shortcode_content = ''

if called from a non self-closing shortcode, the content

Default value''Details
Type
string
See
\TINA_MVC\tina_mvc_shortcode_func()  
>VPropertyprotectedobject $template_vars

View data for passing to a template. Contains 2 objects, one for escaped data and one for non escaped data

Details
Type
object
See
\TINA_MVC\$this->add_var()  
See
\TINA_MVC\$this->add_var_e()  
>VPropertyprotectedstring $the_post_content

the controllers output

Details
Type
string
>VPropertyprotectedstring $the_post_title

the controllers output

Details
Type
string
>VPropertyprotectedarray $tina_mvc_page

the Tina MVC page

Details
Type
array
>VPropertypublicboolean $use_dispatcher = TRUE

whether to use the dispatcher method after creating an instance of the derived class.

Default valueTRUEDetails
Type
boolean
See
\TINA_MVC\$this->dispatcher()  

Methods

methodpublic__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.

Parameters
NameTypeDescription
$requestarray

the Tina MVC request

$called_fromstring

'PAGE_FILTER', 'WIDGET', 'SHORTCODE' or 'CALL_CONTROLLLER_FUNC'

methodpublicadd_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

Parameters
NameTypeDescription
$keystring

the object property name to use when adding data

$vmixed

variable to add

$escboolean

whether to escape data or not

Returns
TypeDescription
boolean
Details
See
\TINA_MVC\$this->template_vars  
See
\TINA_MVC\$this->add_var_e()  
See
\TINA_MVC\$this->load_view()  
methodpublicadd_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()

Parameters
NameTypeDescription
$keystring

the object property name to use when adding data

$vmixed

variable to add

Returns
TypeDescription
boolean
Details
See
\TINA_MVC\$this->view_Data  
See
\TINA_MVC\$this->add_var()  
See
\TINA_MVC\$this->load_view()  
methodpublicdispatch() : 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'

methodpublicget_post_content() : string

Gets the Wordpress Tina MVC page content

Used by tina_mvc_controller_class

Returns
TypeDescription
string
methodpublicget_post_title() : string

Gets the Wordpress Tina MVC page title

Used by tina_mvc_controller_class

Returns
TypeDescription
string
methodprivateinclude_model(string $f, string $m) : mixed

Includes a model

The same search order is used as for controllers

Parameters
NameTypeDescription
$fstring

the full path and filname

$mstring

the model name

Returns
TypeDescription
mixedthe model object or FALSE
methodpublicindex() : 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

methodpublicload_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}

Parameters
NameTypeDescription
$modelstring

the name of the model file (without '_model.php')

$custom_folderstring

path to load the model from

Returns
TypeDescription
objectan instance of the model class
methodpublicload_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

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.

Parameters
NameTypeDescription
$viewstring

the name of the view file (without '_view.php')

$Vmixed

variable (usually array or object) passed to the included file for parsing by the template

$custom_folderstring

an overriding location to load the view from (relative to the Tina MVC plugin folder)

Returns
TypeDescription
stringthe parsed view file (usually HTML)
Details
See
\TINA_MVC\$this->view_data  
methodpublicmail(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.

Parameters
NameTypeDescription
$tomixed

The recipients address (array or string)

$ccmixed
$bccmixed
$subjectstring
$message_templatestring

Template to use (without the '_email.php')

$message_variablesarray

Data to be merged into the message (usually array or object )

Returns
TypeDescription
boolean
Details
Todo
sending attachments  
methodprivateparse_view_file(string $f, mixed $V, boolean $add_html_comments = TRUE) : mixed

Includes and parses a view file or an email file

Parameters
NameTypeDescription
$fstring

full path and filename to file

$Vmixed

the view data

$add_html_commentsboolean

Add HTML comments at the start and end of the view file

Returns
TypeDescription
mixedFALSE or the parsed view file
methodpublicset_called_from(string $c = 'PAGE_FILTER') : void

Setter

Parameters
NameTypeDescription
$cstring
methodpublicset_post_content(string $str) : void

Sets the Tina MVC page content from your application

Parameters
NameTypeDescription
$strstring
methodpublicset_post_title(string $str) : void

Sets the Tina MVC page title from your application

Parameters
NameTypeDescription
$strstring
methodpublicset_request(string $request = array(), string $raw_request = '') : void

Sets the Tina MVC raw_request (handy to have if you need the original uri)

Parameters
NameTypeDescription
$requeststring
$raw_requeststring

\TINA_MVC\tina_mvc_model_class

Package: Tina-MVC\Core
The 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

>VPropertypublicobject $DB
The $wpdb object.

It is public in case we want to run arbitrary SQL

Details
Type
object
>VPropertypublicobject $wpdb
The $wpdb object.

It is public in case we want to run arbitrary SQL

Details
Type
object

Methods

methodpublic__construct() : void

Constructor

The load_model() function will assign these variables in case you forget to call the parent constructor from your derived model class.

\TINA_MVC\tina_mvc_page_class

Package: Tina-MVC\Core
The 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

>VPropertyprotectedmixed $CONTROLLER
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $MODEL
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $allow_http_redirects
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $called_from
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $find_app_file_error
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $is_404
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $raw_request
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $request
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $tina_mvc_page
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed
>VPropertyprotectedmixed $view_data
Tina MVC does nopt support direct access to class variables.

Use setters and getters.

Details
Type
mixed

Methods

methodpublic__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.

Parameters
NameTypeDescription
$raw_requestString

a path /tina_mvc-page/controller/method/and/other/data/to/pass

$role_to_viewBoolean

FALSE allows all to view; '' must be loogged in to view; array or comma separated list of roles to view

$capability_to_viewBoolean

as for $role_to_view. Overrides the $role_to_view

$called_fromString

'PAGE_FILTER', 'WIDGET', 'SHORTCODE' or 'CALL_CONTROLLLER_FUNC'

$custom_folderBoolean

custom location for the controller

$shortcode_contentObject
methodprivatedo_login() : Boolean

Displays and processes a login form

Used if a user is not authorised to view. Forces a login

Returns
TypeDescription
BooleanTRUE if user passed authentication
methodprivateget_instance_of(string $folder = '', string $shortcode_content) : boolean

An autoloader

Parameters
NameTypeDescription
$folderstring
$shortcode_contentstring
Returns
TypeDescription
booleanTRUE on success. FALSE only if called from a shortcode. Other failures trigger an error.
Details
Uses
\TINA_MVC\$this->include_controller()  
methodpublicget_post_content() : string

Gets the Wordpress Tina MVC page content

Returns
TypeDescription
string
methodpublicget_post_title() : string

Gets the Wordpress Tina MVC page title

Returns
TypeDescription
string
methodprivateinclude_controller(Boolean $controller_file = FALSE, String $controller_name = '') : object

Include a controller and set up the Tina MVC request

Parameters
NameTypeDescription
$controller_fileBoolean

Full path and filename of controller to include

$controller_nameString

the class to instantiate

Returns
TypeDescription
objectTina MVC controller
methodpublicis_404() : boolean

Getter

Returns
TypeDescription
boolean
methodprivatemerge_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.

Parameters
NameTypeDescription
$p1mixed
$p2mixed
Returns
TypeDescription
mixed
methodpublicpermissions_to_array(mixed $p = FALSE) : mixed

Converts a Tina MVC role or permission entry to an array or FALSE

Parameters
NameTypeDescription
$pmixed
Returns
TypeDescription
mixed
methodprivateset_404() : void

Setter

Documentation was generated by phpDocumentor 2.0.0a12.