【问题标题】:Help me to find $htmlOption Description in Yii帮我在 Yii 中找到 $htmlOption 描述
【发布时间】:2010-10-10 05:41:55
【问题描述】:

我在 API 中搜索但没有成功。 $htmlOption 的键的描述不完整。 我对一些公共方法特别感兴趣,例如“fileField($model, $attribute, $htmlOptions=array ())”和其他 CActiveForm 类。

【问题讨论】:

  • 你弄明白了吗?如果它帮助您理解 $htmlOption 参数,请选择我的答案,或者如果您发现更好的东西,请发布您自己的答案。谢谢你!

标签: php yii


【解决方案1】:

通常,$htmlOptions 数组由生成的 HTML 元素描述。数组实际上是 HTML 元素的“属性”。键是属性名称。因此,如果您使用 CHtml::Image 生成图像,则“src”是有效的 $htmlOption 键。如果您生成 CHtml::Link,则“href”是有效的 $htmlOption 键。

如果您查看文档,CHtml::link() 元素的 $htmlOptions 参数的描述是:

额外的 HTML 属性。除了普通的 HTML 属性外,还可以识别一些特殊属性(请参阅 clientChange 和 tag 了解更多详细信息。)

我通常使用 $htmlOptions 数组向 HTML 元素添加类、ID 或样式,如下所示:

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

这将呈现以下代码:

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

Yii 允许在 $htmlOptions 数组中为某些元素(链接、按钮和其他一些)提供一些额外的“特殊”AJAX 选项。它们让您创建 AJAX 链接、添加 JS 确认弹出窗口等。这些选项在此处描述:

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

对于 fileField 元素,您可以在 $htmlOptions 数组中查找相关属性 here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 2011-06-26
    相关资源
    最近更新 更多