3

I'm new to the Yii framework and I'm trying to access a property of the of a widget let's say CMenu where I want to change the values of some public properties like activeCssClass, firstItemCssClass, lastItemCssClass, htmlOptions etc. so how do you change the property of a widget in Yii.

Details: I'm using Yii version 1.1.12 (Aug 19, 2012) and I'm trying to generate a multilevel menu but I need to change the values of some public class parameters and I don't know how?

4

2 回答 2

2

好吧,通常您在调用小部件时应用所需的值。您将它们设置在小部件类名称之后的小部件调用内的适当数组中。

$this->widget('zii.widgets.CMenu',
    array(
        'items' => $items,
        'id' => 'main_menu',
        'htmlOptions' => array('class' => 'nav'),
        'activeCssClass' => 'active',
        'firstItemCssClass' => 'first_item'
    )
);

但!如果您想在创建一些小部件后应用这些值,但还没有渲染它(非常罕见的情况),您可以这样做:

$widget = $this->beginWidget('application.components.MyOwnWidget');
$widget->public_property = 'aaa';
$widget->renderSomething();
$this->endWidget();
于 2012-09-25T01:06:13.190 回答
0

添加上一个答案,如果您错过了,请不要忘记查看简短的官方文档

于 2012-09-25T05:48:50.550 回答