jeudi 19 février 2015

Yii: edit table-cells of an unserialized attrbut in a view


Vote count:

0




Working with: Yii 1.1.15


I have a model which contains a serialized array (table) in an attribut. Showing this array as a table in a view works fine.


But I want to update the table-cells and then again save the array serialized in the model. And this does not work. The output stops there (*) without errors.


Here you can see what I did:


$model->table contains a serialized array. The unserialized array looks like this:



array(
array('dog', 'cat', 'cow'),
array('meat', 'milk', 'gras'),
)


I unserialize the table in the controller:


controller: contactController.php



$model = Contact::model()->findByPk((int) $id);
$table = unserialize($model->input)

$this->render('contact_form', array(
'model' => $model,
'table' => $table));
}


And now I want to show and edit the array $table in a form as a html-table:


view: 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(); ?>


The output stops before "... textArea ...".


If I only show $table in a view (without a form) it works like a charme:



<table border="2">
<?php foreach ($table as $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?= CHtml::encode($value) ?></td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
<?php ?>
<?php ?>
</table>


Hope this helps to help me :-) How can I get this nice idea working?



asked 27 secs ago







Yii: edit table-cells of an unserialized attrbut in a view

Aucun commentaire:

Enregistrer un commentaire