Tuesday, November 25, 2008

Re: He everyone

hasManyAndBelongsTo should hasAndBelongsToMany

On Nov 25, 3:21 pm, ayomacro <ayma...@gmail.com> wrote:
> Hi everyone, I just started CakePHP and it's awesome to see the
> mechanism of MVC in a whole new way. Compare to Zend it's simpler for
> newbies.
>
> I'm writing my blog application which is almost finished so I can
> paste it on the website for other people to see the complete CakePHP
> Blog 2 application but there is a problem.
>
> I have a Controller named Tag which is the category I set for my Post.
> (Post hasManyAndBelongsTo Tag :: Tag hasManyAndBelongsTo Post)
> A post can be put under any Tag and the Tag will have many posts where
> user can click and see all associated posts of the Tag.
>
> I created my Tag view so a user can click on the Tag and see many
> related Posts under that but it's not working for me. I've tried
> everything I can even though I haven't put much effort into because of
> Job. here is the View.ctp
>
> [PHP] <div class="tag view">
> <h2>Tag</h2>
>                 <tr>
>                         <td><?php echo $tag['Tag']['name']; ?></td>
>                         <td><?php echo $tag['Tag']['longname']; ?></td>
>                 </tr>
> </div>
> <div class="actions">
>         <ul>
>                 <li><?php echo $html->link('List Posts', array('controller'=>
> 'posts', 'action'=>'index')); ?> </li>
>                 <li><?php echo $html->link('New Post', array('controller'=> 'posts',
> 'action'=>'add')); ?> </li>
>         </ul>
> </div>
>
> <div class="related">
>         <h3>Related Posts</h3>
>         <table cellpadding = "0" cellspacing = "0">
>         <tr>
>                 <th>Id</th>
>                 <th>Title</th>
>                 <th>Body</th>
>                 <th>User Id</th>
>                 <th class="actions">Actions</th>
>         </tr>
>         <?php
>                 foreach ($tag['Post'] as $post):
>         ?>
>                 <tr>
>                         <td><?php echo $post['id'];?></td>
>                         <td><?php echo $post['name'];?></td>
>                         <td><?php echo $post['content'];?></td>
>                         <td><?php echo $post['user_id'];?></td>
>                         <td class="actions">
>                                 <?php echo $html->link(__('View', true), array('controller'=>
> 'posts', 'action'=>'view', $post['id'])); ?>
>                                 <?php echo $html->link(__('Edit', true), array('controller'=>
> 'posts', 'action'=>'edit', $post['id'])); ?>
>                                 <?php echo $html->link(__('Delete', true), array('controller'=>
> 'posts', 'action'=>'delete', $post['id']), null, sprintf(__('Are you
> sure you want to delete # %s?', true), $post['id'])); ?>
>                         </td>
>                 </tr>
>         <?php endforeach; ?>
>         </table>
>
>         <div class="actions">
>                 <ul>
>                         <li><?php echo $html->link(__('New Post', true), array
> ('controller'=> 'posts', 'action'=>'add'));?> </li>
>                 </ul>
>         </div>
> </div>
> [/PHP]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: