/www/protected/components/Form.php
PHP | 79 lines | 65 code | 11 blank | 3 comment | 3 complexity | 77ca2d685ba82eb366199bc0e31f76b8 MD5 | raw file
Possible License(s): Apache-2.0, MIT, LGPL-2.1, BSD-2-Clause, CC-BY-SA-3.0, BSD-3-Clause
- <?php
- class Form extends CWidget
- {
- public $model = null;
-
- public function init()
- {
- if ($model === null) {
- throw RuntimeException();
- }
- return;
- }
- public function run()
- {
- }
- protected renderControl($name => $options)
- {
- $template = <<<EOD
- <div class="control-group">
- {label}
- <div class="control">
- {input}
- </div>
- {error}
- </div>
- EOD;
- $label = CHtml::activeLabelEx($model, $name);
- switch ($options['type']) {
- case 'text':
- $input = CHtml::activeTextField($model, $name);
- break;
- case 'password':
- $input = CHtml::activePasswordField($model, $name);
- break;
- case 'checkbox':
- $input = CHtml::activeCheckBox($model, $name);
- break;
- case 'checkboxlist':
- $input = CHtml::activeCheckBoxList($model, $name);
- break;
- case 'radiobuttonlist':
- $input = CHtml::activeRadioButtonList($model, $name);
- break;
- case 'textarea':
- $input = CHtml::activeTextArea($model, $name);
- break;
- default:
- $input = '';
- }
-
- $error = CHtml::error($model, $name);
- }
- /**
- * Возвращает параметры для построения формы
- */
- public static function getOptions($model)
- {
- $result = array();
- foreach ($model->getSafeAttributeNames() as $name) {
- $result['attributes'][$name] = array(
- 'type' => 'text',
- );
- }
- if (!method_exists($model, 'getFormOptions') {
- $formOptions = $model->getFormOptions();
- $result = CMap::mergeArray($result, $formOptions);
- }
- return $result;
- }
- }