0

管理者がユーザーを追加および編集できる画面を作成しました。問題なくユーザーを追加できますが、ユーザーを編集する方法をテストしていたときに、複数のユーザーがいる場合、リストされている最後のユーザーしか編集できないことに気付きました。他のユーザーを編集できません。

これが私のコードです:

<?php foreach ($personel as $person) { ?>
<div id="edituser<?php echo $person['Personel']['id']; ?>" class="modal" style="display:none;">
    <?php
        $edituserformname = "editUser" + $person['Personel']['id'];
    ?>
    <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
        <h3>Edit User - <?php echo $person['Personel']['firstname']; ?> <?php echo $person['Personel']['surname']; ?></h3>
    </div>
    <div class="modal-body iframed">
        <?php echo $
        <?php 
            echo $this->Form->create('Personel', array(
                'class' => 'form-horizontal',
                'id' => $edituserformname
            ));
            echo $this->Form->input('id', array(
                'type' => 'hidden',
                'value' => $person['Personel']['id']
            ));
            echo $this->Form->input('firstname', array(
                'type' => 'text',
                'label' => 'First Name',
                'class' => 'span5',
                'value' => $person['Personel']['firstname']
            ));
            echo $this->Form->input('surname', array(
                'type' => 'text',
                'label' => 'Surname',
                'class' => 'span5',
                'value' => $person['Personel']['surname']
            ));
            echo $this->Form->input('email', array(
                'type' => 'text',
                'label' => 'E-Mail',
                'class' => 'span5',
                'value' => $person['Personel']['email']
            ));
            echo $this->Form->input('companyid', array(
                'type' => 'hidden',
                'value' => $company['Company']['id']
            ));
            echo $this->Form->input('accesslevel', array(
                'label' => 'Access Level',
                'options' => $roles,
                'empty' => 'Select Access Level',
                'class' => 'span5',
                'value' => $person['Personel']['accesslevel']
            ));
            $pocval = array('1' => 'Yes', '0' => 'No');
            echo $this->Form->input('poc', array(
                'label' => 'Point of Contact?',
                'options' => $pocval, 
                'value' => $person['Personel']['poc']
            ));
            echo $this->Form->input('password', array(
                'type' => 'text',
                'label' => 'Password',
                'class' => 'span5',
                'value' => $company['Personel']['password']
            ));
            echo $this->Form->input('telephone', array(
                'type' => 'text',
                'label' => 'Telephone',
                'class' => 'span5',
                'value' => $company['Personel']['telephone']
            ));
            echo $this->Form->input('type', array(
                'type' => 'hidden',
                'value' => '0'
            ));
         ?>
     </div>
    <div class="modal-footer">
        <?php
        echo $this->Form->submit('Save & Close', array(
                'type' => 'submit',
                'class' => 'btn btn-primary',
                'id' => 'editusermodal'
            ));
        echo $this->Form->end();
         ?>
    </div>
</div>
<?php } ?>

この問題を解決するにはどうすればよいですか? 私は iFrame を使用することを考えていましたが、この方法を使用することに消極的です。私はむしろCakePHPを介してそれを行うことができます.

どうもありがとう

4

2 に答える 2

0

iFrame を使用する必要はありません。フォームが正しく閉じられないため、機能しません。

$this->Form->create()andは divの$this->Form->end()外にある必要があります。

次のことを試してください。

<?php
    echo $this->Form->create('Personel', array(
        'class' => 'form-horizontal',
        'id' => $edituserformname
    ));
?>
    <div class="modal-body iframed">
        <?php 
            echo $this->Form->input('id', array(
                'type' => 'hidden',
                'value' => $person['Personel']['id']
            ));
            echo $this->Form->input('firstname', array(
                'type' => 'text',
                'label' => 'First Name',
                'class' => 'span5',
                'value' => $person['Personel']['firstname']
            ));
            echo $this->Form->input('surname', array(
                'type' => 'text',
                'label' => 'Surname',
                'class' => 'span5',
                'value' => $person['Personel']['surname']
            ));
            echo $this->Form->input('email', array(
                'type' => 'text',
                'label' => 'E-Mail',
                'class' => 'span5',
                'value' => $person['Personel']['email']
            ));
            echo $this->Form->input('companyid', array(
                'type' => 'hidden',
                'value' => $company['Company']['id']
            ));
            echo $this->Form->input('accesslevel', array(
                'label' => 'Access Level',
                'options' => $roles,
                'empty' => 'Select Access Level',
                'class' => 'span5',
                'value' => $person['Personel']['accesslevel']
            ));
            $pocval = array('1' => 'Yes', '0' => 'No');
            echo $this->Form->input('poc', array(
                'label' => 'Point of Contact?',
                'options' => $pocval, 
                'value' => $person['Personel']['poc']
            ));
            echo $this->Form->input('password', array(
                'type' => 'text',
                'label' => 'Password',
                'class' => 'span5',
                'value' => $company['Personel']['password']
            ));
            echo $this->Form->input('telephone', array(
                'type' => 'text',
                'label' => 'Telephone',
                'class' => 'span5',
                'value' => $company['Personel']['telephone']
            ));
            echo $this->Form->input('type', array(
                'type' => 'hidden',
                'value' => '0'
            ));
         ?>
     </div>
    <div class="modal-footer">
        <?php
            echo $this->Form->submit('Save & Close', array(
                    'type' => 'submit',
                    'class' => 'btn btn-primary',
                    'id' => 'editusermodal'
                ));
             ?>
    </div>
<?php 
    echo $this->Form->end(); 
?>
于 2012-12-21T13:06:15.397 に答える
0

一度に複数のレコードを編集したい場合は、次を使用できます

$this->Form->input('ModelName.n.field_name', $options);

したがって、それらすべてを実行するには、これをループで実行します。

echo $this->Form->create(); // only one start
foreach($users as $k => $user) {
    echo $this->Form->id(sprintf('Personel.%s.id', $k), array(
         'value' => $user['Personel']['id']
    ));
    echo $this->Form->input(sprintf('Personel.%s.field', $k), array(
         'value' => $user['Personel']['field']
    ));

    // etc
}
echo $this->Form->end(); // only one end

それらをすべて保存するには、使用できますsaveAll()

$this->Personel->saveAll($this->data['Personel']);
于 2012-12-22T14:51:55.557 に答える