So many technologies so little time to evaluate them, so we decide to write "in a nutshell" introduction to Tequila.
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)
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
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!
Setup Tequila
Download
Unzip in a web directory
Give PHP permissions to write in the whole directory (I know but you will not regret it)
Configure (how to)
Test: Browse to yourserver/yourproject/index.php
Create or use an existing database for testing (if it includes relation far better)
Add Tequila tables by running the attached script (in download package or in installation page)
In: your application/includes/config.php modify:
Database connection
Optional: application name, path to framework files if you move them
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:
Jumpstart your project based on your database
Apply your graphic design
Start coding your project your classes or your controller
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.
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!
Modify the CSS to fit your taste under templates/basic/styles.css
Modify the layout CSS: templates/basic/layout.css
Each page / task created has it's own template, just open in your favorite HTML editor.
Copy / Paste "Basic" folder, Rename the copy as you like. You can switch themes in config.php
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..
Tequila is a single entry point framework, everything is accessed at index.php, to run your task
index.php?task=yourtask&mode=yourfunctionincontroller
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:
Replace text for placeholders, "Here goes the product name" -> {productname}
Fields from DB, use the same field name
Labels, try prefixing with lbl for clarity
Find an area that must be repeated? add block tags around it
Example:
<!-- START BLOCK : articles --><tr><td> {articlename} </td></tr><!--END BLOCK : articles -->
You know precisely the actions the user can execute? You can add all controller functions at once, in the controller
Read any Post,Request,Session var you need to use
Call the model to do something
Call the view to display something
Rules to write the controller
Function must be protected or public
Optional you can receive the model and the view
What you can use to make your life easier
SafePost (get/request/session) functions
readPost function to populate objects from the post
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);}
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
Use public functions
Keep your model clean, no post,get,requests, session in here
No output here
No DB connections here
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);}
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
We already saw how to make a template, now how to put the data on it?
What's there to help me?
onliner functions to assign language resources
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
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 }
To create a new language for your system, just copy/paste/rename lang/EN -> lang/YOURLANGCODE
There is a general language file, shared by the whole application
There is a language file for each task
Language entries are grouped in arrays, keep and add groups yourself
Groups of language entries can be assigned in the view using $this->setlang('groupname');
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
Tequila minimizes on the fly
Your files must not contain any errors
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';
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";
No need to, is already included just set the default page to login or browse to: index.php?task=login
Security is ready in Tequila, also a web editor, just browse to:
index.php?task=sec_manager
index.php?task=users
Read more at understanding your security model
(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)
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;
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!