Yii Framework Forum: Remove Renderkeys From Cgridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Remove Renderkeys From Cgridview for email sender Rate Topic: -----

#1 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 10 September 2013 - 06:30 AM

Hi All

I use the widget CGridView and I want to send the generated html to email sender

but the html contains
<div class="keys" title="the url" style="display:none"> that displayed in email (althought the display:none)

renderKeys in run method of CBaseListView generates this code.

How can I remove this line without tricks (preg_replace) or extending the class(es) ?

Thanks
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 907
  • Joined: 19-February 13
  • Location:India

Posted 10 September 2013 - 06:46 AM

can you post thre grid code?

i think you can pass the htmlpotions

like

'htmlOptions' => array('style'=>''),


i am not sure it's work or not
Thanks,
Ankit Modi
Skype : amodi06
0

#3 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 10 September 2013 - 06:53 AM

Unfortunately this is html tag and already has style="display:none"
so I am afraid that have to remove with preg_replace or extend and override the 'run' method of CBaseListView class
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#4 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 907
  • Joined: 19-February 13
  • Location:India

Posted 10 September 2013 - 07:18 AM

i think you can display the

 'value' => 'CHtml::encode($data["device_name"])',


remove the CHtml::encode

'value' => '$data["device_name"]',


can you ple post a gridcode?
Thanks,
Ankit Modi
Skype : amodi06
0

#5 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 10 September 2013 - 07:32 AM

Maggie

As I described, renderKeys generates this div html element (NOT I by column-attribute)
this div used from cgridview for other purpose. (not for displaying)

So this behaviour is independent by the columns or other cgridview settings...

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array
    (
            'name'=>'create_time',
            'name'=>'authorName',
        array(
            'class'=>'CButtonColumn',
        ),
    ),
));

Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#6 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 907
  • Joined: 19-February 13
  • Location:India

Posted 10 September 2013 - 07:41 AM

I think one way is visible property
'columns'=>array(
        array(
          'name'=>'columnName',
          'visible'=>false
            ),
         )


2) second wqy

'filterHtmlOptions' => array('style' => 'display:none'),

Thanks,
Ankit Modi
Skype : amodi06
0

#7 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 10 September 2013 - 09:36 AM

As I mentioned, this is not Column!! All you said referred to columns.

check Also
https://github.com/y...aseListView.php
run method in line 129 and renderKeys method in 188 gerenate always without condition the no-displayed (by css) div...

So if anyone knows or has experience with emails html and cgridview please let give us an another way to do that..
In any case thanks Maggie :)
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#8 User is offline   Rutger 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 16-November 11

Posted 22 September 2013 - 12:27 PM

View PostKonApaz, on 10 September 2013 - 09:36 AM, said:

...
So if anyone knows or has experience with emails html and cgridview please let give us an another way to do that..
In any case thanks Maggie :)


Hi KonApaz,

I had exactly the same problem and went for the preg_replace option. If anyone needs it, here is my code:

$grid = $this->widget('bootstrap.widgets.TbGridView',
	array(
		'id'=>'events',
		... [your normal grid code here] ...
	),
	true);
		
echo preg_replace('%<div class="keys".*?</div>%s', '', $grid);


Please note the 'true' in the widget call to return the output( see also: http://www.yiiframew...r#widget-detail)

Regards,
Rutger
0

#9 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 23 September 2013 - 03:57 AM

Hi Rutger

As I posted in the beginning of this Topic I try to avoid preg_match.
But I didn't find a way to do that without it, so I implemented something like your code.
In any case thanks :)
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#10 User is offline   explorer 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 26-July 13

Posted 23 September 2013 - 06:03 AM

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();
	}

0

#11 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 23 September 2013 - 06:27 AM

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.

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) ;)
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#12 User is offline   explorer 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 26-July 13

Posted 23 September 2013 - 10:40 PM

View PostKonApaz, on 23 September 2013 - 06:27 AM, said:

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.

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 :)

Quote

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) ;)

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..
0

#13 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 24 September 2013 - 03:29 AM

View Postexplorer, on 23 September 2013 - 10:40 PM, said:

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);
	}

Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#14 User is offline   Trejder 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,257
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 24 September 2013 - 04:28 AM

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.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
1

#15 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 25 September 2013 - 02:46 AM

View PostTrejder, on 24 September 2013 - 04:28 AM, said:

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.



Hi Trejder

About your first answer:
I agree with you, but this strange issue occurs to gmail! (...the other css styles works perfectly...)
I could believe the google has no modern e-mail system! In any case I override the class as should be done, now it works perfectly.

I am glad you to agree with me about the development parctices :)
It is the best and correctly way for OOP programming, I give you a vote :)
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#16 User is offline   eotz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 05-February 15

Posted 15 September 2015 - 05:38 AM

View PostKostas Apazidis (KonApaz), on 25 September 2013 - 02:46 AM, said:

Hi Trejder

About your first answer:
I agree with you, but this strange issue occurs to gmail! (...the other css styles works perfectly...)
I could believe the google has no modern e-mail system! In any case I override the class as should be done, now it works perfectly.

I am glad you to agree with me about the development parctices :)
It is the best and correctly way for OOP programming, I give you a vote :)


i guest you can add

.keys{
	display:none !important
}


in your css file. sorry if im wrong
0

#17 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 15 September 2015 - 09:22 AM

View Posteotz, on 15 September 2015 - 05:38 AM, said:

i guest you can add

.keys{
	display:none !important
}


in your css file. sorry if im wrong


Hi eotz

This article is very old and I dont remember how to achieve it,
I think by extend the CGridView

You cannot add external css style in email
Your solution works for the web appearance but not for emails :)

https://css-tricks.c...the-real-story/
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users