Yes, you can do it that way too. But if you set up the associations,
you don't NEED to change $uses to include Ugroup, as it will
automatically be included based on it's association with the User
model.
On Dec 12, 9:22 am, avairet <[EMAIL PROTECTED]> wrote:
> Hello,
>
> My cake knowledge is limited too (2 months), but I think you must
> specify your 2 models in your controller.
>
> Something like that in PHP5 context:
> <?
> class UsersController extends AppController
> {
> public $uses = array('User','Ugroup');}
>
> ?>
>
> And maybe you should specify the association in your 2 models...
>
> Something like that:
> <?
> class User extends AppModel
> {
> public $belongsTo = array('Ugroup');}
>
> ?>
>
> and for the associated model:
>
> <?
> class Ugroup extends AppModel
> {
> public $hasMany = array('User');}
>
> ?>
>
> And finally, you must indicate to your models, the primary key you are
> using, because by default Cake search for an "id" key to make
> associations.
> <?
> class Ugroup extends AppModel
> {
> public $primaryKey = 'ugroup_id';}
>
> ?>
>
> I hope this helps you...
>
> BR
>
> Avairet
>
> On 12 déc, 08:37, Sanfly <[EMAIL PROTECTED]> wrote:
>
> > No good im afraid, same error, except ugroup_id is now ugroupid
>
> > --------------------------------------------------------------------
> > Notice: Undefined property: UsersController::$Ugroup in C:\server\www
> > \cake\basic_site\plugins\users\controllers\users_controller.php on
> > line 34
>
> > Fatal error: Call to a member function findByUgroupid() on a non-
> > object in C:\server\www\cake\basic_site\plugins\users\controllers
> > \users_controller.php on line 34
> > --------------------------------------------------------------------
>
> > On Dec 12, 7:31 pm, chad <[EMAIL PROTECTED]> wrote:
>
> > > try findByUgroupId
>
> > > On Dec 11, 10:08 pm, Sanfly <[EMAIL PROTECTED]> wrote:
>
> > > > Hi
>
> > > > Ive only just started mucking around with CakePHP, and am having a
> > > > little trouble getting my head around the controllers and models
> > > > thingees. YES - I have tried looking in the manual!!
>
> > > > Im trying to make a cake website that will more or less mirror some
> > > > normal-non-framework php sites I have done.
>
> > > > There is a table called users where all normal user data is stored
> > > > (see below for table structure). The ugroup table contains a
> > > > ugroup_name and a number of "permissions" that dictate what the user
> > > > will be able to access on the site. The ugroup_id field in users
> > > > indicates which ugroup the user belongs to.
>
> > > > When the person logs in, I first want it to check that the user_name
> > > > and user_pass are valid, then access the ugroups table to set the
> > > > ugroup data (permissions) as sessions, which can then be called when I
> > > > like throughout the rest of the site.
>
> > > > users_controller.php
> > > > -----------------------------------------
> > > > <?php
> > > > class UsersController extends AppController
> > > > {
>
> > > > function login()
> > > > {
> > > > $this->set('error', false);
>
> > > > if (!empty($this->data))
> > > > {
> > > > $someone = $this->User->findByUser_name($this->data['User']
> > > > ['user_name']);
>
> > > > if(!empty($someone['User']['user_pass']) &&
> > > > $someone['User']['user_pass'] == md5($this->data['User']
> > > > ['user_pass']))
> > > > {
> > > > $this->Session->write('User', $someone['User']);
>
> > > > // Here is the code that is giving me
> > > > problems
> > > > $perms =
> > > > $this->Ugroup->findByUgroup_id($someone['User']
> > > > ['user_group']);
>
> > > > if($perms['Ugroup']['perm_admin'] ==
> > > > "1"){
> > > >
> > > > $this->redirect('/pages/admin/');
> > > > }
> > > > else{
> > > > $this->redirect('/');
> > > > }
> > > > // End Problem code
> > > > }
> > > > else
> > > > {
> > > > $this->set('error', true);
> > > > }
> > > > }
> > > > }
>
> > > > function logout()
> > > > {
> > > > $this->Session->delete('User');
>
> > > > $this->redirect('/');
> > > > }}
>
> > > > ?>
>
> > > > ----------------------------------------------------------
> > > > However, this code gives me an error:
>
> > > > ----------------------------------------------------------
> > > > Notice: Undefined property: UsersController::$Ugroup in C:\server\www
> > > > \cake\basic_site\plugins\users\controllers\users_controller.php on
> > > > line 34
>
> > > > Fatal error: Call to a member function findByUgroup_id() on a non-
> > > > object in C:\server\www\cake\basic_site\plugins\users\controllers
> > > > \users_controller.php on line 34
> > > > ----------------------------------------------------------
>
> > > > Can anyone point me in the right direction to solve this? Sorry, but
> > > > my cake knowledge is very limited and Im having trouble finding "cake
> > > > for dummies" tutorials :s
>
> > > > Thanks for any help :)
>
> > > > ------------------------------------------------------
> > > > My tables:
>
> > > > CREATE TABLE `users` (
> > > > `user_id` int(25) NOT NULL auto_increment,
> > > > `user_name` varchar(70) NOT NULL default '',
> > > > `user_pass` varchar(70) NOT NULL default '',
> > > > `ugroup_id` int(25) NOT NULL,
> > > > `user_email` varchar(50) NOT NULL default '',
> > > > `user_active` enum('0','1') NOT NULL default '0',
> > > > `user_logged` datetime NOT NULL default '0000-00-00 00:00:00',
> > > > `user_display` varchar(30) NOT NULL default '',
> > > > `user_joined` datetime NOT NULL default '0000-00-00 00:00:00',
> > > > `user_access` enum('0','1') NOT NULL default '0',
> > > > `user_bio` text NOT NULL,
> > > > `user_web` varchar(200) NOT NULL,
> > > > PRIMARY KEY (`user_id`),
> > > > KEY `ugroup_id` (`ugroup_id`)
> > > > ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
>
> > > > ALTER TABLE `users`
> > > > ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`ugroup_id`) REFERENCES
> > > > `ugroups` (`ugroup_id`);
>
> > > > CREATE TABLE `ugroups` (
> > > > `ugroup_id` int(25) NOT NULL auto_increment,
> > > > `ugroup_name` varchar(70) NOT NULL default '',
> > > > `ugroup_rank` int(10) NOT NULL,
> > > > `perm_admin` enum('0','1') NOT NULL default '0',
> > > > `perm_configweb` enum('0','1') NOT NULL default '0',
> > > > `perm_setperm` enum('0','1') NOT NULL default '0',
> > > > `perm_adduser` enum('0','1') NOT NULL default '0',
> > > > `perm_edituser` enum('0','1') NOT NULL default '0',
> > > > `perm_viewuserhidden` enum('0','1') NOT NULL default '0',
> > > > `perm_viewusers` enum('0','1') NOT NULL default '0',
> > > > `perm_addgroup` enum('0','1') NOT NULL default '0',
> > > > `perm_editgroup` enum('0','1') NOT NULL default '0',
> > > > `perm_viewgroup` enum('0','1') NOT NULL default '0',
> > > > PRIMARY KEY (`ugroup_id`)
> > > > ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---