The View
In Tequila the view is made with PHP code, a consequence of keeping the template clean is that the code that links the model to the template has to be added somewhere.. For us this is the view.
Location,
Add the file:
includes/app/views/ categories_view.php
The code
1 <?php 2 class categories_view extends application_view_crud { 3 protected $idfield = 'I_IDCATEGORY'; 4 protected $controller_type = 'categories'; 5 public function show_view(&$vo) 6 { 7 $this->addtitle(); 8 $v = new view_object($this->template,$vo, array('parent'=>'View')); 9 $v->addlang('label'); 10 $v->addlang('msg', 'delete_confirm'); 11 $v->addlang('btn'); 12 $v->getview(); 13 } 14 public function show_edit(&$vo, $isnew = false) 15 { 16 $this->addtitle(); 17 $this->addJS('ajax.js'); 18 $v = new view_editor($this->template, $vo, array('parent'=>'Edit')); 19 $v->addlang('label'); 20 $next_mode = ($isnew ? 'Insert':'Update'); 21 $v->addLabel('mode', $next_mode); 22 $exitUrl = "?task=categories&I_IDCATEGORY={I_IDCATEGORY}&mode=" . ($isnew ? 'Browse' : 'View'); 23 $v->addbtn('submit', ''); 24 $v->addbtn('exit', $exitUrl); 25 $v->addbtn('saveajax','?task=categories&mode=saveAjax&rrt=xmlt'); 26 $v->getview(); 27 } 28 } 29 ?>
What's that code?
Let's see..
First you can notice there's only 2 modes, again we use inheritance to solve common methods
You will notice there's no template assignments (check after)
You can also notice we use $v (see view strategies later on this document)
We assign lang resources (see next step, language files)
View strategies
When we start coding we noticed most of the code of the view was creating blocks and assigning values, so we decided to create a set of strategies to render most common views, you will find this view under
Tequila_fwk/includes/views
This views solve most common problems saving you work without taking out versatility (you are not forced to use naming or anything else) see view strategies section for more info
Current view include
Alternate table
array
editor
loop
loop with grouping
object
organizational chart
page tables
pagination
YUI dynamic tree
YUI fixed tree
XML data
XML complex data
XML status
I have some very complex screens I would like to reuse
You can call the same view from different controllers or you can create a strategy and reuse among many applications, making a strategy is not hard, it actually takes moving your code to one function, extending view_strategy and changing the hardcoded sections. see view_strategies section for more info
I need a template assignment and to create my block manually, what can i do?
You can use normal template methods, the template is available as an object of the class under: $this->template
For creating a block:
$this->template->newBlock("blockname"); or $this->addblock("blockname");
For assigning a value:
$this->template->assign("placeholder", $vo->property);
Language file assignment
Language files resources can be assigned individually or collectively, the structure of a language file is in arrays (see next section the language file) so you can call
$this->setlang("mainarray", "optional_specific_entry");