codeigniter undefined offset erreur

Je suis actuellement en apprentissage système de panier avec CI et a eu quelques problèmes

A PHP Error was encountered 
Severity: Notice
Message: Undefined offset: 2
Filename: models/main_model.php
Line Number: 241

voici le code:

Contrôleur:

function update_cart(){
    $this->main_model->validate_update_cart();
    redirect('cart');
}

Modèle:

function validate_update_cart(){

    //Get the total number of items in cart
    $total = $this->cart->total_items();

    //Retrieve the posted information
    $item = $this->input->post('rowid');
    $qty = $this->input->post('qty');

    //Cycle true all items and update them
    for($i=0;$i < $total;$i++)
    {
        //Create an array with the products rowid's and quantities. 
        $data = array(
           'rowid' => $item[$i], //this is line 241
           'qty'   => $qty[$i]
        );

        //Update the cart with the new information
        $this->cart->update($data);
    }

}

vue:

<div id="main">
<?php if(!$this->cart->contents()):
echo 'You don\'t have any items yet.';
else:
?>
<?php echo form_open('cart/update_cart'); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td style="background-color:yellow;">Qty</td>
<td style="background-color:yellow;">Item No/td>
<td style="background-color:yellow;">Description</td>
<td style="background-color:yellow;">Color</td>
<td style="background-color:yellow;">Price</td>
<td style="background-color:yellow;">Sub-Total</td>
<td style="background-color:yellow;">Delete</td>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach($this->cart->contents() as $items): ?>
<?php echo form_hidden('rowid[]', $items['rowid']); ?>
<tr <?php if($i&1){ echo 'class="alt"'; }?>>
<td>
<?php echo form_input(array('name' => 'qty[]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?>
</td>
<td><a style="font-size:11px;"><?php echo $items['id']?></a></td>
<td><a style="font-size:11px;"><?php echo $items['name']; ?></a></td>
<td><a style="font-size:11px;"><?php echo $items['warna']?></a></td>
<td><a style="font-size:11px;">Rp. <?php echo number_format($items['price'],0,",",".");?></a></td>
<td><a style="font-size:11px;">Rp. <?php echo number_format($items['subtotal'],0,",",".");?></a></td>
<td><a href="<?= base_url();?>cart/delete/<?= $items['rowid'];?>"><img src="<?= base_url();?>assets/image/hapus.png"></img></a></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="5"><strong>Total</strong></td>
<td colspan="2"><a align="right"><?php echo $this->cart->format_number($this->cart->total()); ?></a></td>
</tr>
</tbody>
</table>
<p><?php echo "<input type='submit' class='Button' value='Update'>";?></p>
<?php 
echo form_close(); 
endif;
?>

édité la vue, le code complet.
quand je clique sur le bouton mise à jour, il a renvoyé l'erreur de vivre au-dessus.
merci.

  • Quelle est la valeur que vous attendez-vous à recevoir de $this->input->post('rowid')?
  • le rowid des éléments
  • dans quel format? comme un tableau? pouvez-vous donner un exemple de la valeur?
  • quelle est la valeur de $item?
  • Pouvez-vous nous montrer l'généré le balisage? Peut-être il n'y a pas fermé la balise AVANT le point de vue d'extrait vous nous avez montré...?
  • édité le point de vue
  • Comment $this->cart->total_items() travail?
  • il semble que cela renvoie à quelque chose comme le nombre total d'éléments-je ajouter au panier. par exemple si j'ajoute 300 de la quantité d'un élément, il retourne à 300
  • Mais cela ne reflète que le nombre d'éléments avant que le formulaire est posté, non?
  • essayé de print_r($articles) et j'ai eu cette Array ( [rowid] => 0858ccdaef1d711a2eff18911cf79c51 [id] => 200508000100 [qty] => 300 [warna] => [prix] => 35000.0000 [nom] => BATTERIE HI-TECH H-38 [sous-total] => 10500000 ) 1
  • La deuxième liste n'est pas tellement pertinent à l'erreur. Veuillez voir ma réponse ci-dessous.

InformationsquelleAutor mabbs | 2013-10-30