I started going through the tutorials and everything is fine. I can
enter data in the databse and display it. Now I would like to create an
association and display it.

But I get the following erro in my view: Warning: Invalid argument
supplied for foreach() in
/www/docs/ads.infected-rhythms.com/inbeat/app/views/albums/index.thtml
on line 15

If I unbind before calling findAll() my view is ok again.

To get an idea here is the link:
http://ads.infected-rhythms.com/inbeat/albums

Bassically here is the data model...

I have record albums and each record album has 1 genre associated to
it...

/*************************** tables **************************/

CREATE TABLE albums
(
        id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        title VARCHAR(100) NOT NULL,
        genre_id INT  NOT NULL,
);

CREATE TABLE genres
(
        id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        title VARCHAR(20) NOT NULL
);

/*************************** models **************************/

class Album extends AppModel
{
        var $name = 'Album';

        var $hasOne = array('Genre' =>
                        array('className'    => 'Genre',
                                'conditions'   => '',
                                'order'        => '',
                                'dependent'    =>  false,
                                'foreignKey'   => 'genre_id'
                        )
                );

}

class Genre extends AppModel
{
        var $name = 'Genre';
}

/*************************** controller **************************/

class AlbumsController extends AppController
{
    var $name = 'Albums';

    function index()
    {
           // Put 1 att the end for recursive fetch.
           // If I use unbind here then I get no error, but then I
canot join to my genre table.
          $this->set('albums', $this->Album->findAll(null, null, null,
null, null, 1));
    }
}

/*************************** view **************************/

    <?php foreach ($albums as $album): ?>
    <tr>
        <td><?php echo $album['Album']['title']; ?></td>
        <td><?php echo $album['Album']['description']; ?></td>
        <td><?php echo $album['Album']['genre_id']; ?></td>
        <td><?php echo $album['Album']['release_type']; ?></td>
        <td><?php echo $album['Album']['essential']; ?></td>
        <td><?php echo $album['Album']['created']; ?></td>
    </tr>
    <?php endforeach; ?>

Can anyone see what i'm doing wrong with my view? Thanks!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to