【发布时间】:2016-10-20 03:16:56
【问题描述】:
Yii 版本 1.1.15
我有一个模型,它在属性中包含一个序列化数组(表)。将此数组显示为视图中的表格可以正常工作。
但我想更新表格单元格,然后再次保存模型中序列化的数组。这不起作用。输出在此处停止 (*) 且没有错误。
在这里你可以看到我做了什么:
$model->table 包含一个序列化数组。未序列化的数组如下所示:
array(
array('dog', 'cat', 'cow'),
array('meat', 'milk', 'gras'),
)
我在控制器中反序列化表:
控制器:contactController.php
$model = Contact::model()->findByPk((int) $id);
$table = unserialize($model->input)
$this->render('contact_form', array(
'table' => $table));
}
现在我想以 html-table 的形式显示和编辑数组 $table:
查看:contact_form.php
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'contact-form',
));
?>
<table border="2">
<?php foreach ($table as $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td>
<!-- (*) output stops here, without errors -->
<?= $form->textArea($value, '', array('rows' => 3, 'cols' => 20)); ?>
</td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</table>
<div class="row buttons">
<?php echo CHtml::submitButton("save"); ?>
</div>
<?php $this->endWidget(); ?>
输出在“... textArea ...”之前停止。
如果我只在视图中显示 $table(没有表单),它就像一个魅力:
<table border="2">
<?php foreach ($table as $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?= CHtml::encode($value) ?></td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</table>
希望这对我有所帮助 :-) 我怎样才能让这个好主意发挥作用?
【问题讨论】:
标签: arrays forms serialization yii html-table