嗨,我是 yii 的新手,当我申请练习(RPG 的字符生成器)时,遇到了更新表单问题的问题。我需要更新具有复合 PK 的表。到目前为止,我可以使用我的表单在两个表上创建。但我无法加载更新代码。我的代码如下:
public function actionUpdate($id) {
$model = $this->loadModel($id);
$magicDiffModel = array();
$m = Difficulty::getDifficultyListByType(Difficulty::magicDifficulty);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(!isset($_POST['MagicDifficulty']) && $id != ''){
foreach ($m as $diff => $v) {
$magicDiffModel[$diff] = MagicDifficulty::model()->findAllByPk(array('magic_id' => $id,'difficulty'=>$diff));
}
}else{
}
if (isset($_POST['Magic'])) {
$model->attributes = $_POST['Magic'];
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('update', array(
'model' => $model,
'magicDiffModel' => $magicDiffModel,
'm' => $m,
));
}
<tr>
<td>Zeon</td>
<?php foreach ($m as $id => $name) { ?>
<td><?php echo CHtml::activeTextField($magicDiffModel, '['.$id.']zeon'); ?></td>
<?php } ?>
</tr>
<tr>
<td>Int B.</td>
<?php foreach ($m as $id => $name) { ?>
<td><?php echo CHtml::activeTextField($magicDiffModel, '['.$id.']base_int'); ?></td>
<?php } ?>
</tr>
<tr>
<td>Mantenimiento</td>
<?php foreach ($m as $id => $name) { ?>
<td><?php echo CHtml::activeTextField($magicDiffModel, '['.$id.']manteinance'); ?></td>
<?php } ?>
</tr>
<tr>
<td>Descripción</td>
<?php foreach ($m as $id => $name) { ?>
<td><?php echo CHtml::activeTextField($magicDiffModel, '['.$id.']description'); ?></td>
<?php } ?>
</tr>
这是第一个堆栈项的例外
get_class() expects parameter 1 to be object, array given
/srv/http/animaGen/framework/web/helpers/CHtml.php(2117): get_class(array(1 => array(MagicDifficulty), 2 => array(MagicDifficulty), 3 => array(MagicDifficulty), 4 => array(MagicDifficulty)))
return get_class($model).$sub.'['.$attribute.']';
这是否可能。注意:我理解错误,但想不出解决方案。