PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/www/protected/components/Form.php

https://bitbucket.org/badenkov/demo
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
  1. <?php
  2. class Form extends CWidget
  3. {
  4. public $model = null;
  5. public function init()
  6. {
  7. if ($model === null) {
  8. throw RuntimeException();
  9. }
  10. return;
  11. }
  12. public function run()
  13. {
  14. }
  15. protected renderControl($name => $options)
  16. {
  17. $template = <<<EOD
  18. <div class="control-group">
  19. {label}
  20. <div class="control">
  21. {input}
  22. </div>
  23. {error}
  24. </div>
  25. EOD;
  26. $label = CHtml::activeLabelEx($model, $name);
  27. switch ($options['type']) {
  28. case 'text':
  29. $input = CHtml::activeTextField($model, $name);
  30. break;
  31. case 'password':
  32. $input = CHtml::activePasswordField($model, $name);
  33. break;
  34. case 'checkbox':
  35. $input = CHtml::activeCheckBox($model, $name);
  36. break;
  37. case 'checkboxlist':
  38. $input = CHtml::activeCheckBoxList($model, $name);
  39. break;
  40. case 'radiobuttonlist':
  41. $input = CHtml::activeRadioButtonList($model, $name);
  42. break;
  43. case 'textarea':
  44. $input = CHtml::activeTextArea($model, $name);
  45. break;
  46. default:
  47. $input = '';
  48. }
  49. $error = CHtml::error($model, $name);
  50. }
  51. /**
  52. * Возвращает параметры для построения формы
  53. */
  54. public static function getOptions($model)
  55. {
  56. $result = array();
  57. foreach ($model->getSafeAttributeNames() as $name) {
  58. $result['attributes'][$name] = array(
  59. 'type' => 'text',
  60. );
  61. }
  62. if (!method_exists($model, 'getFormOptions') {
  63. $formOptions = $model->getFormOptions();
  64. $result = CMap::mergeArray($result, $formOptions);
  65. }
  66. return $result;
  67. }
  68. }