Yii Framework Forum: More smart $htmlOptions - Yii Framework Forum

Jump to content

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

More smart $htmlOptions something simple and plain

#1 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 21 October 2011 - 02:08 PM

I don't know the plan about how html elements will be rendered on Yii 2.0 but if the lovely $htmlOptions property will be around I expect to be more "smart".
I have found ( specially when designing extensions ) that the 1 level limitation of this property is annoying.
Most common case is the 'class' when I have to merge default options with the once use has provided. Something like:

$default = array( "class"=>array("default"));//merged with
$specific = array("class"=>array("spec"));//and end up to

...class="default spec"... Could be real nice and handy.

Considering HTML5 data used more and more,it would be nice if I could do something like:

$htmlOptions = array("data"=>array("id"=>1, "name"=>"tydeas"));
and as a result ...data-id=1 data-name="tydeas" in my element.

This post has been edited by tydeas_dr: 26 October 2011 - 07:05 AM

Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,346
  • Joined: 12-October 09
  • Location:Croatia

Posted 21 October 2011 - 03:57 PM

In your example wouldn't be easier and less typing to just write data-id and data-name ?

For the other example... what if someone need a different thing... that the "spec" overwrites the "default" ?
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 22 October 2011 - 04:16 AM

Yes if you know that there are 2 params for the data it could be easier. But what if you have a json that you need to decode and pass as data params? Wouldn't it be more handy just to set data to the array? Imho having something:
$htmlOptions['data']=CJSON::decode($json);

rather
foreach(CJSON::decode($json) as $key => $value)
{ $htmlOptions['data-'.$key] = $value; }


Is much more less typing and more clear. Other example could be $htmlOptions['data'] = $model->attributes;

Related to the overwritting of the class, I thought about it too. And as thing get smarter they get more complex as well.
Taking the creation of an extension as an example, the author of the extension is the one how decides if the option will be able to ovewritten or not. So from this aspect if you set the class property to as string it will overwriten in merging but if you set into an array it won't be overwritten but merged.
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,346
  • Joined: 12-October 09
  • Location:Croatia

Posted 22 October 2011 - 05:20 AM

Can you explain me the use of json for configuring PHP... I use it only on the JS side...
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 22 October 2011 - 06:24 AM

Please don't take this examples too strict. Json encoded data may occure on server side as well imho. If you feel the example was bad stict to the model attributes that really possible.
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,346
  • Joined: 12-October 09
  • Location:Croatia

Posted 22 October 2011 - 01:39 PM

I would just like to see a real life example for the functioning you are requesting... as for json... I don't see the point of using json array in PHP... PHP has it's array..
Find more about me.... btw. Do you know your WAN IP?
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