Myref class library
Added by useful on May-25-2007, 10:30 am
This PHP class library is designed for PHP-programmers and Web-designers to make their management of select, checkbox and radio lists easy and comfortable.
Every PHP-programmer faces the task of outputting a large number of lists (references) like either ?select? element or ?checkbox? and ?radio? on the HTML-page.
The core (maybe it would be better point) is that generally there are many such lists on the page and it takes a lot of time and efforts to work with the large amount of lists and references.
Every list is actually stored in a separate table of a database and is extracted from it by its own specific request.
If there are many of lists, the page code becomes too complicated to cope with. Moreover, if the system has been developed for a long time, it suddenly becomes clear that every reference should work in several languages at the same time, for example, in English, Russian and German. And program code becomes more and more inexplicable and complicated with every such upgrade of the page.
So, we need a perfect tool for the comfortable work with any reference and it should work with all system references at once and provide them with a single API.
This tool is Myref class library which solves two main tasks: it gets lists from database for further output on the HTML-page and provides administrative script for inputting the references into the database.
How can the list be displayed with myref library?
For example, if you need to show ?gender? and ?job function? lists on your HTML-page then execute only one command in your script:
$refs = $refController->getReferences(array( ?gender?, ?job_ function? ));
The reaction of the library on this command will be:
var_dump($refs);
array(2) {
["job_function"]=>
array(3) {
["design"]=>
string(17) "Making web design"
["prog"]=>
string(11) "Programming"
["srs"]=>
string(31) "Preparing Software Requirements"
}
["gender"]=>
array(2) {
["f"]=>
string(6) "Female"
["m"]=>
string(4) "Male"
}
}
Then we need to output all received values onto the HTML-page. Only one command is required for this in Smarty ( http://smarty.php.net ):
$tpl->assign($refs);
In the HTML-templates lists are created in a similar simple way:
{html_options name=gender options=$gender}
{html_options name=job_function options=$job_ function }
The ordinary way of displaying the list is the following:
<select name=?gender?>
<?php
foreach ($refs[?gender?] as $key=>$val) {
echo ?<option value=\?$key\?>$val</option>\n?;
}
?>
</select>
And one more similar block for the job_function reference. All is quite simple?
Bookmark
Category: PHP » Scripts and Programs » Database Tools