Case Study: Handling MySQL Growth With a PHP Class - Formmode
(Page 4 of 5 )
What is the class variable called $formmode? Well, let's say that you want the field published to be a checkbox in your form. The tricky part is to check if the field is check or not checked, especially with the save() function we use in this object.
To solve this, I added another method to WSDynamicObject called addFormModeField;
function addFormModeField( $fieldname, $behaviour ) {
$this->formmode[] = array($fieldname, $behaviour);
} Although the naming of the function could have been better, the functionality works, and the method is used like this from the WSDocument class:
// Form Mode Behaviour
$this->addFormModeField("published","checkbox"); This simply says that the field published should be treated as a checkbox, so when we add a form to create or update an instance of WSDocument, we call the method:
$myobj->formMode(); The function formMode() runs through the array formmode, and set the value to checked if the value is 1 and sets it blank if the value is 0. When the object is saved, the reversed action makes sure that checked = 1 in your MySQL table.
Next: Conclusion >>
More MySQL Articles
More By Bjorn Roysland