YiiFoundation
  • Namespace
  • Class
  • Tree

Namespaces

  • foundation
    • enum
    • exception
    • helpers
    • widgets
      • base
  • PHP

Classes

  • Input
  • Widget
 1 <?php
 2 /**
 3  * @copyright Copyright &copy; 2amigOS! Consulting Group 2013-
 4  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 5  * @package foundation.components
 6  * @version 1.0.0
 7  */
 8 namespace foundation\widgets\base;
 9 
10 use foundation\exception\InvalidConfigException;
11 
12 /**
13  * Input is the base class for widgets that collect user inputs.
14  *
15  * @see http://foundation.zurb.com/docs/components/dropdown.html
16  *
17  * @author Antonio Ramirez <amigo.cobos@gmail.com>
18  * @package foundation\widgets
19  */
20 class Input extends Widget
21 {
22     /**
23      * @var CModel the data model associated with this widget.
24      */
25     public $model;
26     /**
27      * @var string the attribute associated with this widget.
28      * The name can contain square brackets (e.g. 'name[1]') which is used to collect tabular data input.
29      */
30     public $attribute;
31     /**
32      * @var string the input name. This must be set if {@link model} is not set.
33      */
34     public $name;
35     /**
36      * @var string the input value
37      */
38     public $value;
39 
40 
41     /**
42      * @return array the name and the ID of the input.
43      * @throws \foundation\exception\InvalidConfigException
44      */
45     protected function resolveNameID()
46     {
47         if ($this->name !== null)
48             $name = $this->name;
49         elseif (isset($this->htmlOptions['name']))
50             $name = $this->htmlOptions['name']; elseif ($this->hasModel())
51             $name = \CHtml::activeName($this->model, $this->attribute); else
52             throw new InvalidConfigException(\Yii::t(
53                 'yii',
54                 '{class} must specify "model" and "attribute" or "name" property values.',
55                 array('{class}' => get_class($this))
56             ));
57 
58         if (($id = $this->getId(false)) === null) {
59             if (isset($this->htmlOptions['id']))
60                 $id = $this->htmlOptions['id'];
61             else
62                 $id = \CHtml::getIdByName($name);
63         }
64 
65         return array($name, $id);
66     }
67 
68     /**
69      * @return boolean whether this widget is associated with a data model.
70      */
71     protected function hasModel()
72     {
73         return $this->model instanceof CModel && $this->attribute !== null;
74     }
75 }
YiiFoundation API documentation generated by ApiGen 2.8.0