My favorites | Sign in
yii
Project Home Downloads Issues Source
Checkout   Browse   Changes    
 
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
80
81
<?php
/**
* CInputWidget class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

/**
* CInputWidget is the base class for widgets that collect user inputs.
*
* CInputWidget declares properties common among input widgets. An input widget
* can be associated with a data model and an attribute, or a name and a value.
* If the former, the name and the value will be generated automatically.
* Child classes may use {@link resolveNameID} and {@link hasModel}.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.web.widgets
* @since 1.0
*/
abstract class CInputWidget extends CWidget
{
/**
* @var CModel the data model associated with this widget.
*/
public $model;
/**
* @var string the attribute associated with this widget.
* The name can contain square brackets (e.g. 'name[1]') which is used to collect tabular data input.
*/
public $attribute;
/**
* @var string the input name. This must be set if {@link model} is not set.
*/
public $name;
/**
* @var string the input value
*/
public $value;
/**
* @var array additional HTML options to be rendered in the input tag
*/
public $htmlOptions=array();


/**
* @return array the name and the ID of the input.
*/
protected function resolveNameID()
{
if($this->name!==null)
$name=$this->name;
else if(isset($this->htmlOptions['name']))
$name=$this->htmlOptions['name'];
else if($this->hasModel())
$name=CHtml::activeName($this->model,$this->attribute);
else
throw new CException(Yii::t('yii','{class} must specify "model" and "attribute" or "name" property values.',array('{class}'=>get_class($this))));

if(($id=$this->getId(false))===null)
{
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$id=CHtml::getIdByName($name);
}

return array($name,$id);
}

/**
* @return boolean whether this widget is associated with a data model.
*/
protected function hasModel()
{
return $this->model instanceof CModel && $this->attribute!==null;
}
}

Change log

r3527 by qiang.xue on Dec 31, 2011   Diff
1.1.9 release.
Go to: 
Sign in to write a code review

Older revisions

r3515 by mdomba on Dec 28, 2011   Diff
removed 1.0.x reference from
documentation
r2799 by qiang.xue on Jan 1, 2011   Diff
changed copyright year.
r1678 by qiang.xue on Jan 7, 2010   Diff
modified copyright info.
All revisions of this file

File info

Size: 2185 bytes, 81 lines

File properties

svn:keywords
Id
Powered by Google Project Hosting