开发者

Help me to find $htmlOption Description in Yii

开发者 https://www.devze.com 2023-01-19 13:26 出处:网络
I searched in API without success. There is an incomplete description of the keys of $htmlOption. I am particula开发者_运维技巧rly interested in some public methods like \"fileField($model, $attribute

I searched in API without success. There is an incomplete description of the keys of $htmlOption. I am particula开发者_运维技巧rly interested in some public methods like "fileField($model, $attribute, $htmlOptions=array ())" and others of class CActiveForm.


In general, the $htmlOptions array is described by the HTML element being generated. The array is literally the "attributes" of the HTML element. The keys are the attributes names. So if you are generating an image with CHtml::Image then "src" is a valid $htmlOption key. If you generating a CHtml::Link, then "href" is a valid $htmlOption key.

If you look in the documentation, the description for $htmlOptions parameter of the CHtml::link() element is:

additional HTML attributes. Besides normal HTML attributes, a few special attributes are also recognized (see clientChange and tag for more details.)

I usually use the $htmlOptions array to add classes, IDs or styles to an HTML element, like so:

<?php echo CHtml::link("Click Me","http://stackoverflow.com",array("id"=>"myId","class"=>"class1 class2","style"=>"color: #f00;")); ?>

This would render the following code:

<a href="http://stackoverflow.com" id="myId" class="class1 class2" style="color: #f00;">Click Me</a>

There are a couple of extra "special" AJAX options that Yii allows in the $htmlOptions array for some elements (link, button, and a few others). They let you create AJAX links, add JS confirm popups, etc. These options are described here:

http://www.yiiframework.com/doc/api/CHtml#clientChange-detail

For the fileField element, you can look up the relevant attributes here which will be allowed in the $htmlOptions array.

0

精彩评论

暂无评论...
验证码 换一张
取 消