频道栏目
首页 > 资讯 > Yii > 正文

Yii框架中如何清除CPortlet自带的div及class属性

16-01-07        来源:[db:作者]  
收藏   我要投稿

要解决这个问题研究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属性的效果:
tportlet

相关TAG标签
上一篇:thinkphp之3.1版本自动验证
下一篇:用php去除网页中html标签
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站