I haven't ever tried this, but I think that $this->User->Usertype-
>find() needs to be $this->User->Usertype->findAll() if you want to
get a list of all the different user types.
Best way to do this - use bake to make your views, then see how it
handles this.
On Jan 19, 3:57 pm, judouk <[EMAIL PROTECTED]> wrote:
> Sorry guys - another newbie question.
>
> I've got an install of cake 1.2
> I have a users table which I have associated with a usertypes table.
>
> My database setup (cut down for simplicity) is;
>
> create table usertypes (
> id int(10) not null auto_increment,
> choice varchar(100) not null,
> ) type = myisam;
>
> create table users (
> id int(10) not null auto_increment,
> username varchar(15) not null,
> usertype_id int(10) not null,
> ) type = myisam ;
>
> So, what I'm trying to do is to create a new view/controller to add a
> new user.
> However, I also want to use a selection of the usertypes.
>
> I've gone through various applications (and thoroughly confused
> myself!) but have ended up creating two models;
> user.php
> <?php
> class User extends AppModel
> {
> var $name = 'User';
> var $belongsTo = array(
> 'Usertype' => array(
> 'className' => 'Usertype',
> 'conditions' => '',
> 'order' => '',
> 'foreignKey' => 'usertype_id'
> )
> );
>
> }
>
> usertype.php
> <?php
> class Usertype extends AppModel
> {
> var $name = 'Usertype';
> var $hasMany = array(
> 'User' => array(
> 'className' => 'User',
> 'conditions' => '',
> 'order' => '',
> 'foreignKey' => 'usertype_id'
> )
> );
> };
> ?>
>
> My controller (again, very much cut down) is
> <?php
> class UsersController extends AppController
> {
> var $name = 'Users';
> var $helpers = array('Html', 'Form');
> function register()
> {
> if (!empty($this->data))
> {
> // i'll do some validation here
> } else {
> $this->set('usertypes', $this->User->Usertype->find());
> $this->render();
> }
> }}
>
> ?>
>
> I think the line which is wrong is
> $this->set('usertypes', $this->User->Usertype->find());
> but I'm not sure.
>
> Ultimately, I want to be able to do something like
>
> <form action="<?php echo $html->url('/users/register'); ?>"
> method="post">
> <div class="optional">
> <?php echo $form->labelTag('Users/usertype_id',
> 'Username'); ?>
> <?php echo $html->selectTag('Users/usertype_id',
> $usertypes, $html->tagValue('Users/usertype_id'), array(), array(),
> true); ?>
> <?php echo $html->tagErrorMsg('Users/usertype_id', 'Please
> select a user type.'); ?>
> </div>
> <div class="submit">
> <?php echo $form->submit('Add'); ?>
> </div>
> </form>
>
> although this may be wrong too.
>
> Hopefully, I've provided enough info (possibly too much).
>
> Please help.
>
> Thanks
> J
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---