Pergunta

I searched in API without success. There is an incomplete description of the keys of $htmlOption. I am particularly interested in some public methods like "fileField($model, $attribute, $htmlOptions=array ())" and others of class CActiveForm.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top