Tina MVC Install and Quick Start Tutorial

Install

The hard(ish) way

Download from the Wordpress Plugin Directory (preferred download location) or from the Tina MVC page on SeeIT.org.

Unzip and activate as usual.

The easy way

Install straight from within Wordpress.

Hello World in Minutes

Once Tina is active, the default installation gives you a `front end page controller` which is basically a page called `Tina MVC for Wordpress` with a post (page) name (or URL slug) `tina-mvc-for-wordpress`. It will catch any calls to the Tina front end page controller and pass them on to your page controller. Confused…? Don’t worry – read on:

Fire up your text editor and create a new PHP file. Our “Hello World” page controller looks like this:

<?php
 
class hello_world_page extends tina_mvc_base_page_class {
 
    function __construct( $request ) {
 
        parent::__construct( $request );
 
        $this->set_post_title( 'Happy ' . date('l') );
        $this->set_post_content( 'Hello World!' );
 
    }
 
}
 
?>

Save the file as ‘hello_world_page.php’ and upload it to the `/wp-content/plugins/tina-mvc/app/` folder on your Wordpress site.

Now for the fun…

1. Call it using the default front end controller

Navigate to /tina-mvc-for-wordpress/hello-world on your Wordpress site. Tina will intercept the page call and replace the title and content of the post by whatever you want. In this case the post/page title will be ‘Happy <whatever>’ and the post/page content ‘Hello World’.

2. Use the Tina MVC Widget

Look for the ‘Tina MVC Widget’, drag it to the sidebar of your choice and enter the following settings:

Wordpress Widget Page

  • Default Widget Title: Whatever you want – it will be overridden in your page controller anyway
  • Visible to all users: Checked. This disables any permissions checks.

Save, and navigate to your Wordpress home page. You should see your ‘Hello World!’ widget in whatever sidebar you dropped it in.

3. Use the Tina MVC shortcode

In any post or page use the following shortcode:

[ tina_mvc controller='hello-world'] (make sure you lose the space between the opening brakcet ‘[‘ and ‘tina_mvc’.

Note, you don’t see the page title when you use the Tina shortcode (for obvious reasons).

If you don’t see the ‘Hello World’ message you will quite likely see a pretty ugly error message. As Tina’s intended use is in development, I didn’t do any fancy error handling.

Main Points

  • Your page controller files go in the `tina-mvc/app/` folder.
  • They are named the same as the controller name, with hyphens ‘-’ replaced by underscores ‘_’ and with ‘_page.php’ appended.
  • The class is named the same as above (without the .php extension).
  • They should extend the tina_mvc_base_page_class.

For example:

http://example.com/tina-mvc-for-wordpress/hello-world

is mapped on to

hello_world_page class

in the file

wp-content/plugins/tina-mvc/app/hello_world_page.php

Where Next?

Look at the `sample_apps` folder and copy the contents to `app`. Everything there is documented and will demonstrate some more features of Tina, including how to use separate view files, and how to use the forms helper.

And please share your experiences and code!

Fran.

Leave a Reply