作者:千片叶 | 来源:互联网 | 2014-05-16 09:11
要解决这个问题研究CPortlet源码必不可少,CPortlet源码位于zii.widgets.CPortlet.php文件中,里面定义的几个方法都很简单,粗粗一略就知道哪些代码控制了给实际内容套上的div,及相关的id和class属性,当然这里的代码最好是不要改的,我选择继承自CPortlet定义一个子类TPortlet.php:
Yii::import('zii.widgets.CPortlet');
class TPortlet extends CPortlet
{
public $title;
public $hideOnEmpty=true;
private $_openTag;
public function init()
{
ob_start();
ob_implicit_flush(false);
$this->_openTag=ob_get_contents();
ob_clean();
}
/**
* Renders the content of the portlet.
*/
public function run()
{
$this->renderContent();
$cOntent=ob_get_clean();
if($this->hideOnEmpty && trim($content)==='')
return;
echo $this->_openTag;
echo $content;
}
/**
* Renders the decoration for the portlet.
* The default implementation will render the title if it is set.
*/
protected function renderDecoration()
{
if($this->title!==null)
{
}
}
/**
* Renders the content of the portlet.
* Child classes should override this method to render the actual content.
*/
protected function renderContent()
{
}
}
将这个文件放到components文件夹下供其他组件调用,即可实现去掉默认CPortlet自带的div及class属性的效果: