I think because it’s hard coded in the run method in CBaseListView, there’s no way to prevent it from being displayed, other than extending CGridView and implement our own run method or replacing the html directly (eg. using preg_replace).
public function run()
{
$this->registerClientScript();
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
$this->renderContent();
$this->renderKeys();
echo CHtml::closeTag($this->tagName);
}
I’m just curious, why is it hard coded there? while renderContent is actually able to call renderKeys if we mention it in $this->template just like ‘{summary}\n{items}\n{pager}’.
public function renderContent()
{
ob_start();
echo preg_replace_callback("/{(\w+)}/",array($this,'renderSection'),$this->template);
ob_end_flush();
}
[size=2]ok, the only one way without ‘preg_…something’ is overrides a lot of stauff (classes) and I wan’t to do that for this action.[/size]
May be I didn’t use the appropriate phrase “hard coded”. I mean it is better to make something directly rather than to make something and change it later (2 steps - more complex - more consuming - maybe more code)
actually you just need to extend 1 class (CGridView), but of course it’s up to you to choose the best way to do it
You’re talking about your code or CBaseListView? Sorry if I was not clear, but my curiosity was about CBaseListView class itself. I’m wondering why they hard coded renderKeys there, while renderContent is actually able to call it if we specify it in the $template property. Never mind, not a big deal though…
Actually I have to extend the CGridView and use it
Because the CGridView has not ‘run’ method (inherits it from CBaseListView) I have to override the ‘run’ method of CBaseListView without use parent::run(), so the final code is
public function run()
{
$this->registerClientScript();
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
$this->renderContent();
//do not use this... $this->renderKeys();
echo CHtml::closeTag($this->tagName);
}
Let me drop my personal opinion to your first and last post.
First. Most modern e-mail clients, that can handle and operate on HTML-rich e-mail content does fully (or nearly fully) support CSS styles as well. Which means, that if you see “<div class=“keys” title=“the url” style=“display:none”>” in your message, then it is not Yii or code problem, but an incorrect e-mail client configuration or maybe its core engine? I don’t know. All I know, is that, when I was using display:none or any other CSS style, all e-mail clients, that I tested does supported CSS styling and does hidden content, that was marked by me as hidden.
Last. Yes, you’re right. If you’re going to change something that is coded different in framework core, you should most certainly use class extending to own, private classes. This is most usable, reusable and follows modern development practices. So, as you correctly figured out, using preg_replace is a bad idea here.