Package | zii.widgets |
---|---|
Inheritance | abstract class CBaseListView » CWidget » CBaseController » CComponent |
Subclasses | CGridView, CListView |
Since | 1.1 |
Source Code | framework/zii/widgets/CBaseListView.php |
Property | Type | Description | Defined By |
---|---|---|---|
actionPrefix | string | the prefix to the IDs of the actions. | CWidget |
controller | CController | Returns the controller that this widget belongs to. | CWidget |
dataProvider | IDataProvider | the data provider for the view. | CBaseListView |
emptyCssClass | string | the CSS class name for the container of the emptyText property. | CBaseListView |
emptyTagName | string | the HTML tag name for the container of the emptyText property. | CBaseListView |
emptyText | string | the message to be displayed when dataProvider does not have any data. | CBaseListView |
enablePagination | boolean | whether to enable pagination. | CBaseListView |
enableSorting | boolean | whether to enable sorting. | CBaseListView |
htmlOptions | array | the HTML options for the view container tag. | CBaseListView |
id | string | Returns the ID of the widget or generates a new one if requested. | CWidget |
itemsCssClass | string | the CSS class name for the container of all data item display. | CBaseListView |
loadingCssClass | string | the CSS class name that will be assigned to the widget container element when the widget is updating its content via AJAX. | CBaseListView |
owner | CBaseController | Returns the owner/creator of this widget. | CWidget |
pager | array|string | the configuration for the pager. | CBaseListView |
pagerCssClass | string | the CSS class name for the pager container. | CBaseListView |
skin | mixed | the name of the skin to be used by this widget. | CWidget |
summaryCssClass | string | the CSS class name for the summary text container. | CBaseListView |
summaryTagName | string | the HTML tag name for the container of the summaryText property. | CBaseListView |
summaryText | string | the summary text template for the view. | CBaseListView |
tagName | string | the tag name for the view container. | CBaseListView |
template | string | the template to be used to control the layout of various sections in the view. | CBaseListView |
viewPath | string | Returns the directory containing the view files for this widget. | CWidget |
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__construct() | Constructor. | CWidget |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
actions() | Returns a list of actions that are used by this widget. | CWidget |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | 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() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
createWidget() | Creates a widget and initializes it. | CBaseController |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | 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() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
getController() | Returns the controller that this widget belongs to. | CWidget |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getId() | Returns the ID of the widget or generates a new one if requested. | CWidget |
getOwner() | Returns the owner/creator of this widget. | CWidget |
getViewFile() | Looks for the view script file according to the view name. | CWidget |
getViewPath() | Returns the directory containing the view files for this widget. | CWidget |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
init() | Initializes the view. | CBaseListView |
raiseEvent() | Raises an event. | CComponent |
registerClientScript() | Registers necessary client scripts. | CBaseListView |
render() | Renders a view. | CWidget |
renderContent() | Renders the main content of the view. | CBaseListView |
renderEmptyText() | Renders the empty message when there is no data. | CBaseListView |
renderFile() | Renders a view file. | CBaseController |
renderInternal() | Renders a view file. | CBaseController |
renderItems() | Renders the data items for the view. | CBaseListView |
renderKeys() | Renders the key values of the data in a hidden tag. | CBaseListView |
renderPager() | Renders the pager. | CBaseListView |
renderSummary() | Renders the summary text. | CBaseListView |
run() | Renders the view. | CBaseListView |
setId() | Sets the ID of the widget. | CWidget |
widget() | Creates a widget and executes it. | CBaseController |
Method | Description | Defined By |
---|---|---|
renderSection() | Renders a section. | CBaseListView |
the data provider for the view.
the CSS class name for the container of the emptyText property. Defaults to 'empty'.
the HTML tag name for the container of the emptyText property.
the message to be displayed when dataProvider does not have any data.
whether to enable pagination. Note that if the IDataProvider::pagination property of dataProvider is false, this will be treated as false as well. When pagination is enabled, a pager will be displayed in the view so that it can trigger pagination of the data display. Defaults to true.
whether to enable sorting. Note that if the IDataProvider::sort property of dataProvider is false, this will be treated as false as well. When sorting is enabled, sortable columns will have their headers clickable to trigger sorting along that column. Defaults to true.
the HTML options for the view container tag.
the CSS class name for the container of all data item display. Defaults to 'items'. Note, this property must not contain false, null or empty string values. Otherwise such values may cause undefined behavior.
the CSS class name that will be assigned to the widget container element when the widget is updating its content via AJAX. Defaults to 'loading'.
the configuration for the pager. Defaults to array('class'=>'CLinkPager')
.
String value will be treated as the class name of the pager ('ClassName'
value is similar
to the array('class'=>'ClassName')
value). See CBasePager and CLinkPager
for more details about pager configuration array values.
the CSS class name for the pager container. Defaults to 'pager'. Note, this property must not contain false, null or empty string values. Otherwise such values may cause undefined behavior.
the CSS class name for the summary text container. Defaults to 'summary'.
the HTML tag name for the container of the summaryText property.
the summary text template for the view. These tokens are recognized and will be replaced with the corresponding values:
the tag name for the view container. Defaults to 'div'.
the template to be used to control the layout of various sections in the view. These tokens are recognized: {summary}, {items} and {pager}. They will be replaced with the summary text, the items, and the pager.
public void init()
|
public function init()
{
if($this->dataProvider===null)
throw new CException(Yii::t('zii','The "dataProvider" property cannot be empty.'));
$this->dataProvider->getData();
if(isset($this->htmlOptions['id']))
$this->id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$this->id;
if($this->enableSorting && $this->dataProvider->getSort()===false)
$this->enableSorting=false;
if($this->enablePagination && $this->dataProvider->getPagination()===false)
$this->enablePagination=false;
}
Initializes the view. This method will initialize required property values and instantiate columns objects.
public void registerClientScript()
|
public function registerClientScript()
{
}
Registers necessary client scripts. This method is invoked by run. Child classes may override this method to register customized client scripts.
public void renderContent()
|
public function renderContent()
{
ob_start();
echo preg_replace_callback("/{(\w+)}/",array($this,'renderSection'),$this->template);
ob_end_flush();
}
Renders the main content of the view. The content is divided into sections, such as summary, items, pager. Each section is rendered by a method named as "renderXyz", where "Xyz" is the section name. The rendering results will replace the corresponding placeholders in template.
public void renderEmptyText()
|
public function renderEmptyText()
{
$emptyText=$this->emptyText===null ? Yii::t('zii','No results found.') : $this->emptyText;
echo CHtml::tag($this->emptyTagName, array('class'=>$this->emptyCssClass), $emptyText);
}
Renders the empty message when there is no data.
abstract public void renderItems()
|
abstract public function renderItems();
Renders the data items for the view. Each item is corresponding to a single data model instance. Child classes should override this method to provide the actual item rendering logic.
public void renderKeys()
|
public function renderKeys()
{
echo CHtml::openTag('div',array(
'class'=>'keys',
'style'=>'display:none',
'title'=>Yii::app()->getRequest()->getUrl(),
));
foreach($this->dataProvider->getKeys() as $key)
echo "<span>".CHtml::encode($key)."</span>";
echo "</div>\n";
}
Renders the key values of the data in a hidden tag.
public void renderPager()
|
public function renderPager()
{
if(!$this->enablePagination)
return;
$pager=array();
$class='CLinkPager';
if(is_string($this->pager))
$class=$this->pager;
elseif(is_array($this->pager))
{
$pager=$this->pager;
if(isset($pager['class']))
{
$class=$pager['class'];
unset($pager['class']);
}
}
$pager['pages']=$this->dataProvider->getPagination();
if($pager['pages']->getPageCount()>1)
{
echo '<div class="'.$this->pagerCssClass.'">';
$this->widget($class,$pager);
echo '</div>';
}
else
$this->widget($class,$pager);
}
Renders the pager.
protected string renderSection(array $matches)
| ||
$matches | array | the matches, where $matches[0] represents the whole placeholder, while $matches[1] contains the name of the matched placeholder. |
{return} | string | the rendering result of the section |
protected function renderSection($matches)
{
$method='render'.$matches[1];
if(method_exists($this,$method))
{
$this->$method();
$html=ob_get_contents();
ob_clean();
return $html;
}
else
return $matches[0];
}
Renders a section. This method is invoked by renderContent for every placeholder found in template. It should return the rendering result that would replace the placeholder.
public void renderSummary()
|
public function renderSummary()
{
if(($count=$this->dataProvider->getItemCount())<=0)
return;
echo CHtml::openTag($this->summaryTagName, array('class'=>$this->summaryCssClass));
if($this->enablePagination)
{
$pagination=$this->dataProvider->getPagination();
$total=$this->dataProvider->getTotalItemCount();
$start=$pagination->currentPage*$pagination->pageSize+1;
$end=$start+$count-1;
if($end>$total)
{
$end=$total;
$start=$end-$count+1;
}
if(($summaryText=$this->summaryText)===null)
$summaryText=Yii::t('zii','Displaying {start}-{end} of 1 result.|Displaying {start}-{end} of {count} results.',$total);
echo strtr($summaryText,array(
'{start}'=>$start,
'{end}'=>$end,
'{count}'=>$total,
'{page}'=>$pagination->currentPage+1,
'{pages}'=>$pagination->pageCount,
));
}
else
{
if(($summaryText=$this->summaryText)===null)
$summaryText=Yii::t('zii','Total 1 result.|Total {count} results.',$count);
echo strtr($summaryText,array(
'{count}'=>$count,
'{start}'=>1,
'{end}'=>$count,
'{page}'=>1,
'{pages}'=>1,
));
}
echo CHtml::closeTag($this->summaryTagName);
}
Renders the summary text.
public void run()
|
public function run()
{
$this->registerClientScript();
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
$this->renderContent();
$this->renderKeys();
echo CHtml::closeTag($this->tagName);
}
Renders the view. This is the main entry of the whole view rendering. Child classes should mainly override renderContent method.
summaryText is hidden, when there's no data
Keep in mind, that whatever you enter to
summaryText
, will not be displayed, if there is no data.I saw a few Yii projects, where
summaryText
was used to insert a button that called filtering window. The very same button also had to be inserted intoemptyText
, because it would not be available when filtering would result in empty result set.Signup or Login in order to comment.