demo /www/protected/components/Form.php

Language PHP Lines 80
MD5 Hash 77ca2d685ba82eb366199bc0e31f76b8 Estimated Cost $1,507 (why?)
Repository https://bitbucket.org/badenkov/demo View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?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;
    } 
}
Back to Top