PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] Edit table-cells in a view

 February 20, 2022     arrays, forms, html-table, serialization, yii     No comments   

Issue

Yii Version 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(
        '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 ?>
</table>

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


Solution

Actually you are missing the arguments of CactiveForm.textArea(.......)

http://www.yiiframework.com/doc/api/1.1/CActiveForm#textArea-detail

textArea($value, '', array('rows' => 3, 'cols' => 20)); ?>

Instead of it your code should be

textArea($model, $value, array('rows' => 3, 'cols' => 20)); ?>


Answered By - Prasenjit Chakroborty
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing