get post session
Tequila offers some simple functions to simplify access to all this variables.
Reading single values
safeGet, safePost, safeRequest, safeSession
This functions are for reading values from the collection, they just verify if the variable is set and return it's value, otherwise they return false or the optional second parameter
safeGet('myparametername', mydefaultvalue);
The following sections greatly simplify Post handling, if you are comfortable now working with VO's you should use them, Tequila uses them in the CRUD generated pages so you can learn following the code.
* If you prefer to stick to traditional methods for handling your post (we do many times) you can use normal PHP function or the safe methods.
Reading complex values
When you are editing one or many objects in the screen the process of reading the data can be exhausting, Tequila can automatically fill your objects and VO's using the functions provided in application_controller
Reading to VO's
Use the method readpost, this method receive the VO you want to fill as a parameter allowing you to split the post into specific objects.
Example:
$customer = new customer_VO();
$this->readpost($customer);
$address = new address_VO();
$this->readpost($address);
Now the objects customer and address contain all information submitted.
You can also use the method to update values when the information is incomplete:
Example:
Customer can only edit contact information but not name, idcard, etc.:
$customer = $customer_DAO->get($id);
$this->readpost($customer);
// Now customer have the original values in non submited fields and updated items from post
There are naturally some limitations on this methods
Post variables must be named after the object properties
Object properties must have different names
Reading multiple VO's
There are two methods provided to read multiple VO's in the same post, i.e. Multiple addresses in the same form, or multi object editing.
readpost_serialized(string $votype)
Return a collection (array) of objects of type votype, this function complements with the view strategy: view_serialized_objects.
When using the view strategy :
Objects properties become serialized names, i.e.
$address_VO->I_CITY;
Will become:
I_CITY_0, I_CITY_1... in the form
Then you can use this method to retrieve all the submitted values.
readpost_multiple($key, $votype)
Reads an structured post into a set of VO's
@param String $key - Post key
@param String $votype - object type to return (cannot be generic)
example of post format
[fields] => Array
(
[I_SUPPLIER] => Array
(
[fieldname] => I_SUPPLIER
[datatype] => varchar(10)
[nullable] => YES
[control] => Text
)....
Can be read with:
$this->readpost_multiple('fields', 'fields_VO');
This method complements well when values are organized and send to be saved using javascript, you can use the following function to format your data:
function js2php(obj,path,new_path) {
if (typeof(path) == 'undefined') var path=[];
if (typeof(new_path) != 'undefined') path.push(new_path);
var post_str = [];
if (typeof(obj) == 'array' || typeof(obj) == 'object') {
for (var n in obj) {
post_str.push(js2php(obj[n],path,n));
}
}
else if (typeof(obj) != 'function') {
var base = path.shift();
post_str.push(base + (path.length > 0 ? '[' + path.join('][') + ']' : '') + '=' + encodeURI(obj));
path.unshift(base);
}
path.pop();
return post_str.join('&');
}
* This function is part of ajax.js on release version