In a nutshell

So many technologies so little time to evaluate them, so we decide to write "in a nutshell" introduction to Tequila.

What is it?

PHP framework for quick, ordered, faster development. 

For the spec oriented: MVC, Object oriented, UTF8, templates, multiple languages, multiple databases, Data access objects, Value objects, Security ready, User management ready, all code workflow ready, (workflow engine and designer will be shipped in next release)

Why it's faster?

  • Help you to jumpstart your project. With a single click you have a basic application.
  • Provides tons of inherited functionality so with few lines of code you get a lot of things done.
  • Provides functions and classes to simplify most programming actions
  • Makes data displaying a breeze using strategies
  • Makes data access a 1 line operation
  • Many packages to do the most common repetitive work
  • Allow you to reuse your code even across projects
  • Code is easy to write, read and maintain because of the MVC division
  • Tequila is easy to extend and overwrite, pretty much nothing to learn to do this.
  • Drop your classes anywhere

Why is better than a normal PHP project?

PHP is great !we love it but code can get very messy very fast, using a well structured development style, splitting and reusing your code you will get a better developed project. Easier to maintain, faster to update, ready to be translated or in the worse case scenario ready to use another database!

Getting ready to test

Setup Tequila
  1. Download
  2. Unzip in a web directory 
  3. Give PHP permissions to write in the whole directory (I know but you will not regret it)
  4. Configure (how to)
  5. Test: Browse to yourserver/yourproject/index.php

A database to jumpstart your application

  1. Create or use an existing database for testing (if it includes relation far better)
  2. Add Tequila tables by running the attached script (in download package or in installation page)

What to configure

In:  your application/includes/config.php modify:
  1. Database connection
  2. Optional: application name, path to framework files if you move them
  3. Optional: Sunrise_path, (if you move it, or your OS have problems founding the path to it)

Depending on your profile / project at this point you might want:

  1. Jumpstart your project based on your database
  2. Apply your graphic design
  3. Start coding your project your classes or your controller

Jumpstart your project

Browse to :
 yourserver/yourproject/index.php?task=addpage

This is Tequila Sunrise package, it will create an XML definition of your application, you can generate now your application with a single click, or add relations and define page by page which controls to use, validation, etc.. (view rad tutorial)

By now you can have all backend ready, some ajax and perhaps many block of your application done.

Even better you can revisit page by page and add validations, change controls, adjust their size, add relations. Don't worry Tequila Sunrise create a backup of your file so you never loose hand made changes.

Apply your design

Header & footer

It's an extended practice in web development to split header and footer, you can find this templates under templates/basic/header.html (and foother.html)
* Be careful with header, there are many sections that MUST be there, just copy them into your template!

CSS

Modify the CSS to fit your taste under templates/basic/styles.css
Modify the layout CSS: templates/basic/layout.css

Style specific pages

Each page / task created has it's own template, just open in your favorite HTML editor.

Create a whole new theme

Copy / Paste "Basic" folder, Rename the copy as you like. You can switch themes in config.php

Start coding your project

Coding in Tequila is very easy, the main issue is to understand how to split your code.

Where to the starting coding depends on you, try:
  • I know the precise functions / classes / model I want to implement ---> Model
  • I have a great design -> Template 
  • I know the actions user can execute -> Controller
  • I want an advanced screen -> Sunrise + template & JS
  • I know the database -> Sunrise or make your VO's and DAO's yourself
First of all, select a name for the task you want to create, invoices, recipes, inventory, subscriptions, etc..

Running your task

Tequila is a single entry point framework, everything is accessed at index.php, to run your task 

index.php?task=yourtask&mode=yourfunctionincontroller

Coding the template

  1. Save your HTML file  templates/basic/taskname.html

What makes a template a template?

Tequila uses template Power a really cool engine that allows no coding, so your designer can easily do it, you just:
  1. Replace text for placeholders,  "Here goes the product name" -> {productname}
    1. Fields from DB, use the same field name
    2. Labels, try prefixing with lbl for clarity
  2. Find an area that must be repeated? add block tags around it 
Example:
<!-- START BLOCK : articles -->
<tr><td> {articlename} </td></tr>
<!--END BLOCK : articles -->

Coding the controller

You know precisely the actions the user  can execute? You can add all controller functions at once, in the controller
  1. Read any Post,Request,Session var you need to use
  2. Call the model to do something
  3. Call the view to display something

Rules to write the controller

  1. Function must be protected or public
  2. Optional you can receive the model and the view

What you can use to make your life easier

  1. SafePost (get/request/session) functions
  2. readPost function to populate objects from the post
  3. readPostSerialized, to populate multiple objects from the post
Example, adding a function to search products that have to be reordered:

protected function getreorder(&$model, &$view)
{
   $reqCategory = safeRequest('category', 'all');
   $data = $model->getreorder($reqCategory);
   $view->showlist($data);
}

Coding the model

The model is any logical class you want to implement normally data access, business rules and all interesting stuff is done here,  you can integrate ANY class you already have or code it

One rule and some advice

  1. Use public functions
  2. Keep your model clean, no post,get,requests, session in here
  3. No output here
  4. No DB connections here
  5. Data access preferred order: DAO, getData, getValue; NON prefered: getRow, getRst
Example:
// Using DAO
public function getreorder($category == "all")
{
    $dao = new inventory_DAO();
    return $dao->getreorder($category);
}
// Using getData
public function getreorder($category =="all)
{
    $mSql = "SELECT * FROM INVENTORY_PRODUCTS WHERE QTY < REORDER";
    return getData ($mSql);
}

Coding the DAO & the VO

The middle point in between your db and your model, you can use:
DAO: To get,save,update,find,count records
VO: To transport data in an object that represents a ROW in your table

Dao takes 3 lines of code: table, votype, keyfield
VO, takes 1 line of code: a list of variables, one per field in the db

Coding the View

We already saw how to make a template, now how to put the data on it?

What's there to help me?

  1. onliner functions to assign language resources
  2. Strategies to display the data in many ways (2 liners)

Basic (suffering mode):

//To create a block:
$this->template->newBlock('blockname');
//To replace a placeholder:
$this->template->assign('placeholdername', $value);
You can create any kind of cycle to assign the data into the template

Advanced (Strategies):

Strategies, are another way of reuse code across applications, there's many strategies you can use check them out in includes/views

Example: Showing the list of products 
  1 // This will create a beautiful sortable table with any product property you want to display
   2 public function showlist($productdata)
   3 {
   4     $v = new view_alternatetable($this->template, $data);
   5     $v->getview();
   6     // To show the same list as XML replace the strategy in line 4
   7     $v = new view_xml_data($this->template, $data);
   8 
   9 }

Language files

To create a new language for your system, just copy/paste/rename  lang/EN -> lang/YOURLANGCODE
  1. There is a general language file, shared by the whole application
  2. There is a language file for each task
  3. Language entries are grouped in arrays, keep and add groups yourself
  4. Groups of language entries can be assigned in the view using $this->setlang('groupname');

Adding your own CSS / JS files

Tequila caches all client resources, so even if you add multiple times the file is requested just one time, you can:
   1 addJS("file1.js,file2,js,file3.js"); //<- one or many
   2 addCSS("file1.css,file2.css");
   3 addJSVar("varname","varValue"); //<- Ever need to pass a value to the JS script?
   4 addJSfromLang ()//<- Pass a JS language file

Minimizing, caching and safe loading your JS

  1. Tequila minimizes on the fly
  2. Your files must not contain any errors
  3. Just find and change in config: 
   $js_safeloading = true;
Tequila will now minimize and save a cached reduced file, it will also safe load the file, retrying until the file is loaded or $js_retry is reached, it can also block the screen for using by setting $js_blocktillcomplete = true;
  $js_safeloading = false;
  $js_blocktillcomplete = true;
  $js_retry = 3;
  $js_cachedir = 'temp';

Setting your application start point and main page

Let's say you want the start point to be login and the main page (after login) to be dashboard
Change in config:
$defaultpage = "login";
$mainpage = "dashboard";

Adding a login page

No need to, is already included just set the default page to login or browse to: index.php?task=login

Managing your users & security

Security is ready in Tequila, also a web editor, just browse to:
index.php?task=sec_manager
index.php?task=users

Mashing up!

(tutorial coming soon)
You can call your pages as blocks from server using getblock(....); or from the browser/client (using rrt querystring parameter). Using rrt you can get a full page, or a block to use inside an iframe or a cleaner piece of code to show in a <div>. JSON and XML are as easily get (check sunrise tutorial)

Creating a workflow task

Tequila is fully workflow compatible and allows complex interactions, multiple screen changes, interruptions etc, this unfortunately makes impossible for Tequila to automatically knows when you have finished, to inform Tequila just add on the controller:
$this->tr->finished = true;

If you task return a result that will change the flow
$this->tr->result = 'your result';
$this->tr->finished = true;
$this->tr->result = true;

Creating workflows

Workflow engine and the designer will be release in version 3.2, we are currently working in the flash based designer which is delaying us, however the engine has been available since version 2.0

Well with this intro in a nutshell, you should be standing on your feet!! 

Read documentation to learn more or get coding :)

Best luck!

Our main page

Recent site activity