Hey guys, I am fairly new to the HABTM usage in cake, I am trying to
setup a simple edit page for a table "channels" that has a HABTM
relationship with "tags" using the join table "channels_tags" in my
view page it successfully see the related tags for the channel, but
when I use the form help and use: <?php echo $form->input('Tag'); ?>
it outputs a muli-select box like it should, but there is no data
inside the box...
Here is the relevant code:
/models/channel.php
<?php
class Channel extends AppModel {
var $name = 'Channel';
var $hasMany = array('Item');
var $hasAndBelongsToMany = array('Tag');
}
?>
/models/tag.php
<?php
class Tag extends AppModel {
var $name = 'Tag';
var $hasAndBelongsToMany = array('Channel', 'Item');
}
?>
/controllers/channels_controller.php
<?php
class ChannelsController extends AppController {
var $name = 'Channels';
var $uses = array('Channel', 'User', 'Tag');
function index() {
$this->set('channels', $this->Channel->find('all'));
}
function view($id) {
$this->set('channel', $this->Channel->findById($id));
$this->set('users', $this->User->find('all'));
}
function edit($id = null) {
if (empty($this->data)) {
$this->set('channel', $this->Channel->findById($id));
}
else {
//do something
}
}
}
?>
/views/channels/edit.ctp
<?php
echo $form->create('Channel', array('action' => 'edit'));
echo $form->input('title');
echo $form->input('Tag');
echo $form->end('Update');
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---