Probleme Illegal string offset 'id'

Par arcoss 3x, il y a 10 ans


bonjour,
je suis actuellement en train de regarder cakephp jour 2 et j ai un probleme, une erreur : Illegal string offset 'id'.
Merci d avance

6 réponses

Lartak, il y a 10 ans

Bonsoir.
Ce n'est pas suffisant comme information.
Il faudrait au grand minimum nous donner l'erreur complète, puis au minimum nous montrer la partie du code mise en cause par rapport à l'erreur.
Car là, juste nous donner : Illegal string offset 'id', ça ne va pas nous permettre de t'aider.

arcoss 3x, il y a 10 ans

code erreur :

Warning (2): Illegal string offset 'id' [APP\View\Medias\admin_index.ctp, line 13]Image 100x100px Warning (2): Illegal string offset 'id' [APP\View\Medias\admin_index.ctp, line 13]Image 400x300px Warning (2): Illegal string offset 'id' [APP\View\Medias\admin_index.ctp, line 13]Image 960x600px Warning (2): Illegal string offset 'id' [APP\View\Medias\admin_index.ctp, line 16]Image originale Warning (2): Illegal string offset 'id' [APP\View\Medias\admin_index.ctp, line 18]Supprimer

admin_index.ctp:

<table> <tr> <th>Image</th> <th>Noms</th> <th>Action</th> </tr> <?php foreach ($medias as $k => $v): $v = current($v); ?> <tr> <td><?php echo $this->Html->image($v['url'],array('style'=>'max-width:200px')); ?></td> <td><?php echo $v['name']; ?></td> <td> <?php foreach($formats as $k=>$v): ?> <?php echo $this->html->link("Image ".$v."px",array('action'=>'show',$v['id'])); ?> <br> <?php endforeach; ?> <?php echo $this->html->link("Image originale",array('action'=>'show',$v['id'])); ?> <br> <?php echo $this->html->link("Supprimer",array('action'=>'delete',$v['id']),null,'Voulez-vous vraiment supprimer l\'image ?'); ?> </td> </tr> <?php endforeach ?> </table> <h3>Ajouter une image</h3> <?php echo $this->Form->create('Media',array('type'=>'file')); ?> <?php echo $this->Form->input('file',array('label'=>"Image (png/jpg) :","type"=>"file")); ?> <?php echo $this->Form->input('name',array('label'=>"Nom de l'image :")); ?> <?php echo $this->Form->end('Ajouter');?> <h3>Depuis le web</h3> <?php echo $this->Form->create('Media'); ?> <?php echo $this->Form->input('url',array('label'=>"URL de l'image :")); ?> <?php echo $this->Form->end('Ins�rer'); ?>
winklevows, il y a 10 ans

Tu fais un foreach dans un foreach en nomant des variables avec le même nom, du coup ton premier tableau (de média) se fait écraser par la chaine qui contient le format

arcoss 3x, il y a 10 ans

Merci mais comment je fais pour regler cette erreur ?

Lartak, il y a 10 ans

Merci mais comment je fais pour regler cette erreur ?

Par exemple, en modifiant :

foreach ($formats as $k => $v):

Par :

foreach ($formats as $p => $q):
arcoss 3x, il y a 10 ans

Merci beaucoup ca fonctionne !!!!