This is a very useful component that can be used to generate an edit form of the data, which is a very important component of the MST Library 3.1, which enables the loop nesting of the dbo form and the dbo form, is controlled in a form, and supports the DBO The custom widget component is nested again in the form. Many PHP frameworks, which write the form generation in the function, are understandable, but you cannot receive the performance cost of iterating over the user function when generating a form, and building a PHP and HTML-mixed code is much better than the performance of the loop execution function. And, most of the time, we know the structure of a data object, we have defined the value type of each field of the data object, we really do not need to manually write what form, or to use the code to judge, this with select, that with textarea or something.
- The image of the pair to manipulate
- $target must be based on Mst_dbo's example
- if (!isset ($data) | |!is_object ($DATA) | |! $data instanceof mst_dbo) {
- Echo ' $data not a mst_dbo instance! ';
- }
- else {
- Get the Contact module
- $model = Get_class ($data);
- Definition $columns
- If undefined, the Mst_dbo interface is taken
- if (!isset ($columns))
- $columns = $data->getformcolumns ($data);
- if (Empty ($columns) | |!is_array ($columns)) {
- echo ' undefine form columns! ';
- }
- else {
- Generate the front able of the module
- if (!isset ($prefix))
- $prefix = Strtolower ($model);
- Else
- $prefix = Mst_string::tableize ($prefix);
- if (!isset ($id))
- $id = $prefix. ' _form ';
- if (!isset ($class))
- $class = $prefix. '-form ';
- $errors = $data->geterrors ();
- Initializing the form configuration
- Customizing the submitted action
- if (!isset ($action))
- $action = $this->params->uri;
- Method
- if (!isset ($method))
- $method = ' post ';
- else {
- $method = Strtolower (string) $method);
- if ($method! = ' Get ' && $method! = ' Post ')
- $method = ' post ';
- }
- Is it necessary to upload the
- if (!isset ($isUpload)) $isUpload = true;
- Customizing the text of the Submit button
- if (!isset ($submitText)) $submitText = ' Submit ';
- Customizing the width of the label part
- if (!isset ($headWidth)) $headWidth = 130;
- $headWidth = Is_numeric ($headWidth) && $headWidth > 0? $headWidth: 120;
- if (!isset ($continueForm)) $continueForm = false;
- Re-download
- if (!isset ($lineStart)) $lineStart = 1;
- ?>
-
-
- }
- }
- ?>
Copy Code
- $this->widget (' Base/dbo_form ', Array (
- ' Data ' = $this->list,
- ));
Copy Code
-
- Class Testimonial extends Mst_dbo {
- protected static
- $columns = Array (
- ' FirstName ' = Array (' text ', ' title ' = ' First Name ', ' require ' = + 1, ' min ' = + 1, ' max ' = 32),
- ' LastName ' = Array (' text ', ' title ' = ' Last Name ', ' require ' = = 1, ' min ' = + 1, ' max ' = 32),
- ' Avator ' = = Array (' title ' = ' Avator ', ' max ' = 256),
- ' Age_group ' = = Array (' title ' = ' age group ', ' require ' + 1),
- ' secret ' = = Array (' textarea ', ' title ' = ' secret ', ' require ' = ' 1, ' min ' = +, ' max ' = 600),
- );
- Public Function Getformcolumns () {
- if (gb_perssions = = Region::root) {
- $columns [' region_id '] = Array (
- ' SELECT ',
- ' Title ' = ' Region ',
- ' Optionstype ' = ' list ',
- ' Options ' = Region::find (' All ', Array (' select ' = ' = ' ID, name ')),
- );
- }
- else {
- $columns [' region_id '] = Array (
- ' Hidden ',
- ' Default ' = Gb_perssions,
- );
- }
- $columns = Array_merge ($columns, Self:: $columns);
- $columns [' age_group '] = Array (' widget ', ' Base/age_group ', Array (
- ' Prefix ' = ' testimonial ',
- , ' title ' = ' Age Group ');
- $columns [' avator '] = Array (' widget ', ' base/testmonial_upload ', Array (
- ' Prefix ' = ' testimonial ',
- ), ' title ' = ' Avator ');
- return $columns;
- }
- Public Function Beforecreate (& $data) {
- $data [' created_at '] = time ();
- }
- Public Function Getage () {
- $ageGroup = Array (
- 0 = '--',
- 1 = ' Under 18 ',
- 2 = ' 19? 25 ',
- 3 = ' 26? 35 ',
- 4 = ' 36? 45 ',
- 5 = ' 46? 55 ',
- 6 = ' or above ',
- );
- return Isset ($ageGroup [$this [' Age_group ']]? $ageGroup [$this [' Age_group ']: $ageGroup [0];
- }
- Public Function Getavator () {
- return empty ($this [' avator '])? Httpuri (' Images/avator.png '): Httpuri ($this [' avator ']);
- }
- This is an overload of the method of find for Mst_dbo
- static public Function Find ($args = Array (), $params = null, $isArray = False) {
- if (defined (' gb_perssions ') && gb_perssions = = region::root) {
- Self::initfind ($args, $params, $isArray);
- Return Parent::find ($args, $params, $isArray);
- }
- else {
- Self::initfind ($args, $params, $isArray);
- if (Isset ($args [' where ')]) {
- $args [' WHERE '][0]. = ' and region_id =? ';
- $args [' where '] = gb_perssions;
- }
- else {
- $args [' where '] = Array (' region_id =? ', gb_perssions);
- }
- Return Parent::find ($args, $params, $isArray);
- }
- }
- }
Copy Code |