Php yii中的形式行为

Php yii中的形式行为,php,yii,Php,Yii,我有一个,它添加了一些带有条件的自定义字段 _form.php $form->attachbehavior('users', new DirectoriesBehavior); // return part of form echo $form->getDirectory(array('sysName' => 'users', 'useDefaultValue' => true)); // Other form parts (default for yii) echo

我有一个,它添加了一些带有条件的自定义字段

_form.php

$form->attachbehavior('users', new DirectoriesBehavior);

// return part of form
echo $form->getDirectory(array('sysName' => 'users', 'useDefaultValue' => true));

// Other form parts (default for yii)
echo $form->labelEx($model, 'name');
$form->getDirectory(array('model' => $model));
$form->id;
DirectoriesBehavior::getDirectory()
使用
等字段构建HTML表单部件

但如何将表单的名称/id发送到我的行为

渲染后,它看起来像

<form method="" id="myForm">
    <!--BEHAVIORS CONTENT-->
    <select>
        <option value="UserId">UserName</option>
    </select>

    <!--Default fields of form-->
    <input type="text" name="myForm[exampleField]" />
</form>
<select name="myForm[users]">
    <option>etc</option>
</select>

用户名
我的行为应该是这样的

<form method="" id="myForm">
    <!--BEHAVIORS CONTENT-->
    <select>
        <option value="UserId">UserName</option>
    </select>

    <!--Default fields of form-->
    <input type="text" name="myForm[exampleField]" />
</form>
<select name="myForm[users]">
    <option>etc</option>
</select>

我解决了这个问题:

我们可以在_form.php中发送$model

$form->getDirectory(array('model' => $model));
在DirectoriesBehavior.php中

public function getDirectory(array $data)
{
    $this->inputName = get_class($data['model']);
}
另外(对于将使用此表单的脚本,我们可以发送表单的ID)

_form.php

$form->attachbehavior('users', new DirectoriesBehavior);

// return part of form
echo $form->getDirectory(array('sysName' => 'users', 'useDefaultValue' => true));

// Other form parts (default for yii)
echo $form->labelEx($model, 'name');
$form->getDirectory(array('model' => $model));
$form->id;

你解决了这个问题?或者只是部分!!请试着在结尾处把遗留问题(问题)部分弄清楚!!