I actually prefer the same “types” to be used in editing and viewing.
For example, if I am working with a date field:
// in the Post class
$validation = array(
'editdate' => array(
'label' => 'Edit Date',
'rules' => array(...),
'type' => 'date'
),
// ...
);
// ------------------
// in a view
$post->view_editdate(); // outputs the field as a formatted date
//or
$post->edit_editdate(); // outputs the field in a textbox, formatted for editing, maybe including a popup calendar for selecting dates.For many formatting types, the editor will just defer to the default single line editor.
For checkboxes, I actually used the phrase “checkbox” both times, since I wanted the field to be rendered as a graphic of a checkbox selected or not:
// in viewer
// renders a field as a checkbox
function checkbox($object, $field) {
$value = $object->${field};
if($value) {
echo 'images/checkbox_checked.png';
} else {
echo 'images/checkbox_unchecked.png';
}
}For selection lists, I either passed in a list of values or I looked up a standard array within the object
// in viewer
function selection($object, $field, $values = NULL) {
$value = $object;
if(is_null($values)) {
// look for values array in both object and class
if(isset($object->{$field.'_values'})) {
$values = $object->{$field.'_values'};
} else if(isset($object::{$field.'_values'})) {
$values = $object::{$field.'_values'};
} else {
show_error("No values defined");
}
}
return htmlspecialchars($values[$value]);
}
// edit method is similar, or shares code with a common function to get the arrayThis allowed me to look up how to render the field for editing or viewing using $this->validation[$field][‘type’].
I also often like to have several options. For example, the select list above could be reformatted as a list of radio buttons, if it made sense. My code has a function called list() that automatically switches to radios for less than 4 items.
Just some ideas, referencing some of the problems I have had. I’ve actually spent a ton of time refining my Html_viewer and Html_editor classes (that I believe you have a copy of, stensi). Even though they are formatted for Dojo, they offer a lot of code for formatting a variety of fields. For example, Dates, Times, and Timestamps can be formatted as ‘SHORT’, ‘MEDIUM’, or ‘LONG’, or custom formatted using the strftime() function.
Probably the biggest concern here is that every user of the system is going to want different formatting for their output, both on view and edit. This is why I am not sure how much you want to include. I think that providing a skeleton for the viewer and editor would be more useful, as it would be a guide for new users on how to add functionality. You can see just how different a simple thing such as a boolean/checkbox field could be rendered (various images, true/false, yes/no, on/off, or even more specific, like lost/found)!