Bonsoir

J'essaye de classer des images par album mais cela ne fonctionne pas, lors du foreach des images, voici le code :

<div class="albums index">
    <h2><?php echo __('Albums');?></h2>
    <table cellpadding="0" cellspacing="0">

<?php debug($albums) ;?>
    <?php foreach ($albums as $album): ?>
    <tr>
        <td><?php echo $album'Album']'id']; ?> </td>
        <td><?php echo $album'Album']'title']; ?> </td>

        <?php foreach ($albums as $album): ?>
            <td><?php echo $album'Galery']'id']; ?> </td>
        <?php endforeach; ?>

    </tr>
<?php endforeach; ?>
    </table>

Le debug de $albums donne ceci :

app\View\Albums\index.ctp (line 5)
Array
(
    [0] => Array
        (
            [Album] => Array
                (
                    [id] => 1
                    [title] => Album1
                )
            [Galery] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [title] => Test
                            [image] => 1
                            [date] => 2011-10-21 19:37:00
                            [album_id] => 1
                        )
                    [1] => Array
                        (
                            [id] => 2
                            [title] => Test2
                            [image] => 2
                            [date] => 2011-10-21 19:47:00
                            [album_id] => 1
                        )
                )
        )
    [1] => Array
        (
            [Album] => Array
                (
                    [id] => 2
                    [title] => Album2
                )
            [Galery] => Array
                (
                    [0] => Array
                        (
                            [id] => 3
                            [title] => Test3
                            [image] => 3
                            [date] => 2011-10-21 19:50:00
                            [album_id] => 2
                        )
                    [1] => Array
                        (
                            [id] => 4
                            [title] => Test4
                            [image] => 4
                            [date] => 2011-10-21 19:51:00
                            [album_id] => 2
                        )
                    [2] => Array
                        (
                            [id] => 5
                            [title] => Test5
                            [image] => 5
                            [date] => 2011-10-21 19:51:00
                            [album_id] => 2
                        )
                )
        )

L'erreur...

1 Album1    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14] 
2 Album2    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14] 
3 Album3    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14] 
4 Album4    
Notice (8): Undefined index: id [APP\View\Albums\index.ctp, line 14]

Flo2315

3 réponses


Flo2315
Auteur
Réponse acceptée

C'est bon j'ai trouvé :)

Merci de ton aide.
Voici la solution :

<div class="albums index">
<h2><?php echo __('Albums');?></h2>
<?php debug($albums) ;?>
<table cellpadding="0" cellspacing="0">
    <?php foreach ($albums as $album): ?>
        <tr>
            <td><?php echo $album'Album']'id']; ?> </td>
            <td><?php echo $album'Album']'title']; ?> </td>
            <?php foreach ($album'Galery'] as $galery): ?>
                <td><?php echo $galery'id']; ?> </td>
            <?php endforeach; ?>
        </tr>
    <?php endforeach; ?>
</table>

Essais donc avec ça

<div class="albums index">
<h2><?php echo __('Albums');?></h2>
<table cellpadding="0" cellspacing="0">
    <?php foreach ($albums as $album): ?>
        <tr>
            <td><?php echo $album'Album']'id']; ?> </td>
            <td><?php echo $album'Album']'title']; ?> </td>
            <?php foreach ($albums'Gallery'] as $gallery): ?>
                <td><?php echo $gallery'id']; ?> </td>
            <?php endforeach; ?>
        </tr>
    <?php endforeach; ?>
</table>
Flo2315
Auteur

Toujours pas, c'est au niveau de Galery je comprend pas.(A oui c'était Galery est non Gallery).

Erreur :

Notice (8): Undefined index: Galery [APP\View\Albums\index.ctp, line 9]
Code Context
include - APP\View\Albums\index.ctp, line 9
View::_render() - CORE\Cake\View\View.php, line 598
View::render() - CORE\Cake\View\View.php, line 365
Controller::render() - CORE\Cake\Controller\Controller.php, line 898
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 114
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 89
[main] - APP\webroot\index.php, line 97
Warning (2): Invalid argument supplied for foreach() [APP\View\Albums\index.ctp, line 9]
Notice (8): Undefined index: Galery [APP\View\Albums\index.ctp, line 9]
Warning (2): Invalid argument supplied for foreach() [APP\View\Albums\index.ctp, line 9]
Notice (8): Undefined index: Galery [APP\View\Albums\index.ctp, line 9]
Warning (2): Invalid argument supplied for foreach() [APP\View\Albums\index.ctp, line 9]
Notice (8): Undefined index: Galery [APP\View\Albums\index.ctp, line 9]
Warning (2): Invalid argument supplied for foreach() [APP\View\Albums\index.ctp, line 9]