We're having trouble with saving a HABTM (of course!). We followed the
example in the manual but still can't get it to work for us in a
similar situation.

Our system tracks employee roles in an organisation. Each employee can
have many roles and there are multiple people also in that role. We
would prefer to use checkboxes instead of a multiple select tag for
aesthetic reasons, but we can't get the list of possible roles to be
pre-checked with the ones already associated with that user.
in our users_controller we do:
$this->set('user_roles',$this->User->Role->generateList() );

then in the View:

foreach($user_roles as $role_id=>$role_name)
{
      echo "<li>".$html->checkbox('Role/id')." ".$role_name."</li>";
}

But this doesn't work... it is our understanding that from this, cake
would be able to check our results set (in $data) and tick it if it
exists.

pr($user_roles) produces this:

Array
(
    [1] => Union Rep
    [2] => Health & Safety Officer
)

pr($data) produces this:

Array
(
    [User] => Array
        (
            [id] => 1
            [created] =>
            [modified] => 2006-05-16 15:37:43
            [username] => root
            [password] => ********
        )

    [Role] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [role_name] => Union Rep
                    [created] => 2006-05-10 17:16:17
                )

        )
)

We can see the Role data is there, but not how to access it properly to
catch the magical abilities of cake.

I know that this is probably a newbie question but we've been through
the manual, tried to trace the cake code, API and wiki, but still can't
find a decent explanation of how to get the HABTM editing working.

Thanks in advance.

p.s. can I have a banana?
love MonkeyBoy xxx


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to