> YII 类库手册 > CPortlet
zii.widgets
继承 class CPortlet » CWidget » CBaseController » CComponent
源自 1.1
版本 $Id: CPortlet.PHP 2799 2011-01-01 19:31:13Z qiang.xue $
源码
CPortlet是用于portlet部件的基类。

一个portlet部件显示的内容一般作为 网页侧边栏的一部分来显示。

如果要自定义portlet部件的内容,需要覆盖renderContent 方法,或将内容插入到CController::beginWidget 和CController::endWidget之间,例如,

<?php $this->beginWidget('zii.widgets.CPortlet'); ?>
    ...在此插入的内容...
<?php $this->endWidget(); ?>


一个portlet部件也有一个可选的title属性用来定义标题。也可以通过覆盖renderDecoration 方法进一步自定义portlet的标题(例如,如增加最小化/最大化按钮)。

公共属性

属性 类型 描述 定义在
actionPrefix string actions的ID的前缀。 当微件在CController::actions中声明了 动作提供者,可以为其动作的ID指定前缀以区别 于别的微件或控制器。当微件用于控制器 的视图中时,必须配置同样的前缀。 CWidget
contentCSSClass string 组件中内容容器的CSS类。默认为‘portlet-content’。 CPortlet
controller CController 返回此微件所属的控制器。 CWidget
decorationCssClass string 组件中标题容器的CSS类。默认为‘portlet-decoration’。 CPortlet
hideOnEmpty boolean 是否在portlet内容为空时隐藏。默认为true。 CPortlet
HTMLOptions array portlet容器的HTML属性。 CPortlet
id string 返回此微件的ID。如果需要的话,将生产一个新的ID并将其返回。 CWidget
owner CBaseController 返回此微件的所有者或创建者。 CWidget
skin mixed 微件使用的皮肤的名称。默认为“default”。 如果此属性设置为false,微件将不会有皮肤被使用。 CWidget
tagName string portlet容器的HTML标签,默认为‘div’。 CPortlet
title string portlet组件的标题内容。默认为空。 当没有设置title时,将不会显示标题。 注意标题渲染时,不会被HTML编码。 CPortlet
titleCssClass string 组件的标题的CSS类。默认为‘portlet-title’。 CPortlet
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() 初始化部件。 CPortlet
raiseEvent() 发起一个事件。 CComponent
render() 渲染一个视图。 CWidget
renderFile() Renders a view file. CBaseController
renderInternal() Renders a view file. CBaseController
run() 渲染portlet的内容. CPortlet
setId() 设置此微件的ID。 CWidget
widget() Creates a widget and executes it. CBaseController

受保护方法

方法 描述 定义在
renderContent() 渲染portlet显示的内容。 CPortlet
renderDecoration() 渲染portlet的标题部分。 CPortlet

属性详细

contentCssClass 属性
public string $contentCssClass;

组件中内容容器的CSS类。默认为‘portlet-content’。

decorationCssClass 属性
public string $decorationCssClass;

组件中标题容器的CSS类。默认为‘portlet-decoration’。

hideOnEmpty 属性 (可用自 v1.1.4)
public boolean $hideOnEmpty;

是否在portlet内容为空时隐藏。默认为true。

htmlOptions 属性
public array $htmlOptions;

portlet容器的HTML属性。

tagName 属性
public string $tagName;

portlet容器的HTML标签,默认为‘div’。

title 属性
public string $title;

portlet组件的标题内容。默认为空。 当没有设置title时,将不会显示标题。 注意标题渲染时,不会被HTML编码。

titleCssClass 属性
public string $titleCssClass;

组件的标题的CSS类。默认为‘portlet-title’。

方法详细

init() 方法
public void init()
public function init()
{
    
ob_start();
    
ob_implicit_flush(false);

    
$this->htmlOptions['id']=$this->getId();
    echo 
CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
    
$this->renderDecoration();
    echo 
"<div class=\"{$this->contentCssClass}\">\n";

    
$this->_openTag=ob_get_contents();
    
ob_clean();
}

初始化部件。 在这里开始渲染portlet的内容部分。 如果设置了标题则同样在这里渲染。

renderContent() 方法
protected void renderContent()
protected function renderContent()
{
}

渲染portlet显示的内容。 子类需要重写此方法来显示自己的内容。

renderDecoration() 方法
protected void renderDecoration()
protected function renderDecoration()
{
    if(
$this->title!==null)
    {
        echo 
"<div class=\"{$this->decorationCssClass}\">\n";
        echo 
"<div class=\"{$this->titleCssClass}\">{$this->title}</div>\n";
        echo 
"</div>\n";
    }
}

渲染portlet的标题部分。 默认显示设置的标题。

run() 方法
public void run()
public function run()
{
    
$this->renderContent();
    
$content=ob_get_clean();
    if(
$this->hideOnEmpty && trim($content)==='')
        return;
    echo 
$this->_openTag;
    echo 
$content;
    echo 
"</div>\n";
    echo 
CHtml::closeTag($this->tagName);
}

渲染portlet的内容.

上一篇: