| 包 | zii.widgets.jui |
|---|---|
| 继承 | class CJuiButton » CJuiInputWidget » CJuiWidget » CWidget » CBaseController » CComponent |
| 源自 | 1.1.3 |
| 版本 | $Id: CJuiButton.php 2799 2011-01-01 19:31:13Z qiang.xue $ |
| 源码 |
CJuiButton显示一个按钮部件。
CJuiButton封装了JUI Button 插件。
使用这个部件当作一个提交按钮,你可以在视图里面插入以下代码:
使用这个部件当作一个按钮,你可以在视图里面插入以下代码:
通过配置options属性, 你可以指定需要传递给JUI button插件的选项。 如果需要选择(name-value pairs), 请参阅JUI Button说明。
CJuiButton封装了JUI Button 插件。
使用这个部件当作一个提交按钮,你可以在视图里面插入以下代码:
$this->widget('zii.widgets.jui.CJuiButton', array(
'name'=>'submit',
'caption'=>'Save',
'options'=>array(
'onclick'=>'js:function(){alert("Yes");}',
),
));
使用这个部件当作一个按钮,你可以在视图里面插入以下代码:
$this->widget('zii.widgets.jui.CJuiButton',
array(
'name'=>'button',
'caption'=>'Save',
'value'=>'asd',
'onclick'=>'js:function(){alert("Save button clicked"); this.blur(); return false;}',
)
);
通过配置options属性, 你可以指定需要传递给JUI button插件的选项。 如果需要选择(name-value pairs), 请参阅JUI Button说明。
公共属性
| 属性 | 类型 | 描述 | 定义在 |
|---|---|---|---|
| actionPrefix | string | actions的ID的前缀。 当微件在CController::actions中声明了 动作提供者,可以为其动作的ID指定前缀以区别 于别的微件或控制器。当微件用于控制器 的视图中时,必须配置同样的前缀。 | CWidget |
| attribute | string | 和这个小物件相关的属性。 这个名称可能包含中括号(例如‘name[1]’),用于搜集表格式的数据输入。 | CJuiInputWidget |
| buttonType | string | 按钮类型(可能的类型:submit,button,link,radio,checkbox,buttonset)。 “submit”是默认使用的。 | CJuiButton |
| caption | string | 按钮的文本 | CJuiButton |
| controller | CController | 返回此微件所属的控制器。 | CWidget |
| CSSFile | mixed | 主题的CSS文件名。默认是‘jquery-ui. | CJuiWidget |
| HTMLOptions | array | JUI组件中HTML标签的属性设置。 | CJuiWidget |
| htmlTag | string | buttonset的默认标签 | CJuiButton |
| id | string | 返回此微件的ID。如果需要的话,将生产一个新的ID并将其返回。 | CWidget |
| model | CModel | 与这个小物件相关的数据模型 | CJuiInputWidget |
| name | string | 输入框名称。如果model没有设置,这个必须设置。 | CJuiInputWidget |
| onclick | string | 这个项被点击时引发的javascript函数(客户端事件)。 | CJuiButton |
| options | array | the 初始的JavaScript需要传递给JUI插件的选项。 | CJuiWidget |
| owner | CBaseController | 返回此微件的所有者或创建者。 | CWidget |
| scriptFile | mixed | 主要JUI的JavaScript的文件名。默认是‘jquery-ui. | CJuiWidget |
| scriptUrl | string | 包含所有JUI JavaScript文件的根目录。 如果没有设置这个属性(默认),Yii will publish the JUI package included in the zii release and use that to infer the root script URL. | CJuiWidget |
| skin | mixed | 微件使用的皮肤的名称。默认为“default”。 如果此属性设置为false,微件将不会有皮肤被使用。 | CWidget |
| theme | string | JUI主题的名字。默认是‘base’。确保在themeUrl下有这样一个目录, 其名称是这个属性的值相同(区分大小写)。 | CJuiWidget |
| themeUrl | string | 包含所有JUI的主题文件夹的根目录。 如果没有设置这个属性(默认), Yii will publish the JUI package included in the zii release and use that to infer the root theme URL. | CJuiWidget |
| url | string | 当一个按钮类型为“link”被选择时使用的URL。 | CJuiButton |
| value | mixed | 当前项的值。仅用于“radio”和“checkbox” | CJuiButton |
| viewPath | string | 返回包含此微件所需的视图文件的路径。 | CWidget |
公共方法
| 方法 | 描述 | 定义在 |
|---|---|---|
| __call() | 如果类中没有调的方法名,则调用这个方法。 | CComponent |
| __construct() | 构造器。 | CWidget |
| __get() | 返回一个属性值、一个事件处理程序列表或一个行为名称。 | CComponent |
| __isset() | 检查一个属性是否为null。 | CComponent |
| __set() | 设置一个组件的属性值。 | CComponent |
| __unset() | 设置一个组件的属性为null。 | CComponent |
| actions() | 返回此widget使用的动作的列表。 | CWidget |
| asa() | 返回这个名字的行为对象。 | CComponent |
| attachBehavior() | 附加一个行为到组件。 | CComponent |
| attachBehaviors() | 附加一个行为列表到组件。 | CComponent |
| attachEventHandler() | 为事件附加一个事件处理程序。 | CComponent |
| beginCache() | Begins fragment caching. | CBaseController |
| beginClip() | Begins recording a clip. | CBaseController |
| beginContent() | Begins the rendering of content that is to be decorated by the specified view. | CBaseController |
| beginWidget() | Creates a widget and executes it. | CBaseController |
| canGetProperty() | 确定属性是否可读。 | CComponent |
| canSetProperty() | 确定属性是否可写。 | CComponent |
| createWidget() | Creates a widget and initializes it. | CBaseController |
| detachBehavior() | 从组件中分离一个行为。 | CComponent |
| detachBehaviors() | 从组件中分离所有行为。 | CComponent |
| detachEventHandler() | 分离一个存在的事件处理程序。 | CComponent |
| disableBehavior() | 禁用一个附加行为。 | CComponent |
| disableBehaviors() | 禁用组件附加的所有行为。 | CComponent |
| enableBehavior() | 启用一个附加行为。 | CComponent |
| enableBehaviors() | 启用组件附加的所有行为。 | CComponent |
| endCache() | Ends fragment caching. | CBaseController |
| endClip() | Ends recording a clip. | CBaseController |
| endContent() | Ends the rendering of content. | CBaseController |
| endWidget() | Ends the execution of the named widget. | CBaseController |
| evaLuateExpression() | 计算一个PHP表达式,或根据组件上下文执行回调。 | CComponent |
| getController() | 返回此微件所属的控制器。 | CWidget |
| getEventHandlers() | 返回一个事件的附加处理程序列表。 | CComponent |
| getId() | 返回此微件的ID。如果需要的话,将生产一个新的ID并将其返回。 | CWidget |
| getOwner() | 返回此微件的所有者或创建者。 | CWidget |
| getViewFile() | 根据视图名查找视图文件。 | CWidget |
| getViewPath() | 返回包含此微件所需的视图文件的路径。 | CWidget |
| hasEvent() | 确定一个事件是否定义。 | CComponent |
| hasEventHandler() | 检查事件是否有附加的处理程序。 | CComponent |
| hasProperty() | 确定属性是否被定义。 | CComponent |
| init() | (non-PHPdoc) | CJuiButton |
| raiseEvent() | 发起一个事件。 | CComponent |
| render() | 渲染一个视图。 | CWidget |
| renderFile() | Renders a view file. | CBaseController |
| renderInternal() | Renders a view file. | CBaseController |
| run() | (non-PHPdoc) | CJuiButton |
| setId() | 设置此微件的ID。 | CWidget |
| widget() | Creates a widget and executes it. | CBaseController |
受保护方法
| 方法 | 描述 | 定义在 |
|---|---|---|
| hasModel() | 确定是否这个小物件与一个数据模型相关。 | CJuiInputWidget |
| registerCoreScripts() | 注册核心的脚本文件。 | CJuiWidget |
| registerScriptFile() | 注册一个JavaScript文件在scriptUrl下。 | CJuiWidget |
| resolveNameID() | CJuiInputWidget | |
| resolvePackagePath() | 确定JUI包安装路径。 | CJuiWidget |
属性详细
buttonType
属性
public string $buttonType;
按钮类型(可能的类型:submit,button,link,radio,checkbox,buttonset)。 “submit”是默认使用的。
caption
属性
public string $caption;
按钮的文本
htmlTag
属性
public string $htmlTag;
buttonset的默认标签
onclick
属性
public string $onclick;
这个项被点击时引发的javascript函数(客户端事件)。
url
属性
public string $url;
当一个按钮类型为“link”被选择时使用的URL。
value
属性
public mixed $value;
当前项的值。仅用于“radio”和“checkbox”
方法详细
init()
方法
|
public void init()
|
public function init(){
parent::init();
if ($this->buttonType=='buttonset')
{
list($name,$id)=$this->resolveNameID();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
if(isset($this->htmlOptions['name']))
$name=$this->htmlOptions['name'];
else
$this->htmlOptions['name']=$name;
echo CHtml::openTag($this->htmlTag, $this->htmlOptions);
}
}
(non-PHPdoc)
参见
- framework/zii/widgets/jui/CJuiWidget::init()
run()
方法
|
public void run()
|
public function run()
{
$cs = Yii::app()->getClientScript();
list($name,$id)=$this->resolveNameID();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
if(isset($this->htmlOptions['name']))
$name=$this->htmlOptions['name'];
else
$this->htmlOptions['name']=$name;
if ($this->buttonType=='buttonset')
{
echo CHtml::closeTag($this->htmlTag);
$cs->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').buttonset();");
}
else
{
switch($this->buttonType)
{
case 'submit':
echo CHtml::submitButton($this->caption, $this->htmlOptions) . "\n";
break;
case 'button':
echo CHtml::htmlButton($this->caption, $this->htmlOptions) . "\n";
break;
case 'link':
echo CHtml::link($this->caption, $this->url, $this->htmlOptions) . "\n";
break;
case 'radio':
if ($this->hasModel())
{
echo CHtml::activeRadioButton($this->model, $this->attribute, $this->htmlOptions);
echo CHtml::label($this->caption, CHtml::activeId($this->model, $this->attribute)) . "\n";
}
else
{
echo CHtml::radioButton($name, $this->value, $this->htmlOptions);
echo CHtml::label($this->caption, $id) . "\n";
}
break;
case 'checkbox':
if ($this->hasModel())
{
echo CHtml::activeCheckbox($this->model, $this->attribute, $this->htmlOptions);
echo CHtml::label($this->caption, CHtml::activeId($this->model, $this->attribute)) . "\n";
}
else
{
echo CHtml::checkbox($name, $this->value, $this->htmlOptions);
echo CHtml::label($this->caption, $id) . "\n";
}
break;
default:
throw new CException(Yii::t('zii','The button type "{type}" is not supported.',array('{type}'=>$this->buttonType)));
}
$options=empty($this->options) ? '' : CJavaScript::encode($this->options);
if (isset($this->onclick))
{
if(strpos($this->onclick,'js:')!==0)
$this->onclick='js:'.$this->onclick;
$click = CJavaScript::encode($this->onclick);
$cs->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').button($options).click($click);");
}
else
{
$cs->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').button($options);");
}
}
}
(non-PHPdoc)
参见
- framework/CWidget::run()