Apologies for another HABTM help topic but I'm having trouble getting
this.

My application is very similiar to a setup where there are tables
'posts' and 'tags' where Post HABTM Tags.  The manual explains how to
set up the database for this situation and how to fill in the Model
code for Post.php however....

1. What should be placed in the Model code for Tag.php? (another HABTM
statement, just vice-versa?)
2. Does there need to be a Model and Controller for the posts_tags
association table.? (I'm assuming 'No')

Then when it comes to saving the associations I use the View code from
the CakePHP manual chapter on HABTM, however....

3. What code needs to go in the controller to save the associations?

Here's the code I've got that doesn't work. (it's pretty much straight
from the manual)

====View Code====

<h1>Write a New Post</h1>
<table>
    <tr>
    <td>Title:</td>
    <td><?php echo $html->input('Post/title')?></td>
    </tr>

    <tr>
    <td>Body:</td>
    <td><?php echo $html->textarea('Post/body')?></td>
    </tr>

    <tr>
    <td>Related Tags:</td>
    <td><?php echo $html->selectTag('Tag/Tag', $tags, null,
array('multiple' => 'multiple')) ?>
    </td>
    </tr>

    <tr>
    <td colspan="2">
    <?php echo $html->submit('Save')?>
    </td>
    </tr>
</table>

====Controller Code====

function add() {
    $this->set('tags', $this->Post->Tag->generateList(null, null,
null, '{n}.Tag.id', '{n}.Tag.tag'));

    if (!empty($this->data)) {
        if ($this->Post->save($this->data)) {
            $this->flash('Your post has been saved.','/posts/index');
        }
    }
}

I really appreciate any help.  Thanks!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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