01.22
php
saved
t73net
Note
I need users and groups to be relational in that a single user may have multiple groups and each group will have multiple users.
Is using a HABTM model structure appropriate here?
I have followed the outline of http://realm3.com/articles/setting_up_user_groups_with_acl_and_auth_in_cakephp_1.2
and have not come up with a solution for the parent_node function in GroupsModel or UsersModel
I need users and groups to be relational in that a single user may have multiple groups and each group will have multiple users.
Is using a HABTM model structure appropriate here?
I have followed the outline of http://realm3.com/articles/setting_up_user_groups_with_acl_and_auth_in_cakephp_1.2
and have not come up with a solution for the parent_node function in GroupsModel or UsersModel
- /**
- * SQL Table Structure Dump
- *
- --
- -- Table structure for table `acos`
- --
- CREATE TABLE `acos` (
- `id` int(11) NOT NULL auto_increment,
- `parent_id` int(11) default NULL,
- `model` varchar(255) collate utf8_bin default NULL,
- `foreign_key` int(11) default NULL,
- `alias` varchar(255) collate utf8_bin default NULL,
- `lft` int(11) default NULL,
- `rght` int(11) default NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=3 ;
- --
- -- Table structure for table `aros`
- --
- CREATE TABLE `aros` (
- `id` int(11) NOT NULL auto_increment,
- `parent_id` int(11) default NULL,
- `model` varchar(255) collate utf8_bin default NULL,
- `foreign_key` int(11) default NULL,
- `alias` varchar(255) collate utf8_bin default NULL,
- `lft` int(11) default NULL,
- `rght` int(11) default NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=11 ;
- --
- -- Table structure for table `aros_acos`
- --
- CREATE TABLE `aros_acos` (
- `id` int(11) NOT NULL auto_increment,
- `aro_id` int(11) default NULL,
- `aco_id` int(11) default NULL,
- `_create` int(11) NOT NULL default '0',
- `_read` int(11) NOT NULL default '0',
- `_update` int(11) NOT NULL default '0',
- `_delete` int(11) NOT NULL default '0',
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ;
- --
- -- Table structure for table `groups`
- --
- CREATE TABLE `groups` (
- `id` smallint(5) unsigned NOT NULL auto_increment,
- `name` varchar(50) collate utf8_bin default NULL,
- `description` text collate utf8_bin,
- `parent_id` int(11) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=10 ;
- --
- -- Table structure for table `groups_users`
- --
- CREATE TABLE `groups_users` (
- `id` int(10) unsigned NOT NULL auto_increment,
- `group_id` int(10) unsigned NOT NULL,
- `user_id` int(10) unsigned NOT NULL,
- `created` datetime default NULL,
- `modified` datetime default NULL,
- PRIMARY KEY (`id`),
- KEY `group_id` (`group_id`,`user_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Group User HABTM Relational Table' AUTO_INCREMENT=2 ;
- --
- -- Table structure for table `users`
- --
- CREATE TABLE `users` (
- `id` int(10) unsigned NOT NULL auto_increment,
- `username` varchar(250) collate utf8_bin NOT NULL default '',
- `password` varchar(250) collate utf8_bin NOT NULL default '',
- `active` tinyint(1) unsigned NOT NULL default '1',
- `created` datetime default NULL,
- `modified` datetime default NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `username` (`username`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='User Data Information' AUTO_INCREMENT=2 ;
- */
- /**
- * /app/models/users.php
- */
- <?php
- class User extends AppModel {
- var $name = 'User';
- var $displayField = 'username';
- 'rule' => 'blank',
- 'on' => 'create'
- ),
- 'message' => 'An account with that username has already been registered.',
- 'on' => 'create'
- )
- ),
- 'rule' => 'alphaNumeric',
- 'message' => 'Only alphabets and numbers allowed',
- 'on' => 'create'
- ),
- 'message' => 'Between 5 to 15 characters'
- )
- ),
- 'rule' => 'alphaNumeric',
- 'message' => 'Only alphabets and numbers allowed',
- 'on' => 'create'
- ),
- 'message' => 'Between 5 to 15 characters'
- )
- )
- );
- 'Group' =>
- 'joinTable' => 'groups_users',
- 'foreignKey' => 'group_id',
- 'associationForeignKey' => 'user_id',
- 'conditions' => '',
- 'order' => '',
- 'limit' => '',
- 'uniq' => true,
- 'finderQuery' => '',
- 'deleteQuery' => '',
- 'insertQuery' => ''
- )
- );
- function checkUnique($data, $fieldName) {
- $valid = false;
- {
- }
- return $valid;
- }
- function parentNode( ) {
- if (!$this->id) {
- return null;
- }
- $data = $this->read();
- if (!$data['User']['group_id']){
- return null;
- } else {
- }
- }
- function validLogin($data)
- {
- $this->user = $user['User'];
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- }
- ?>
- /**
- * /app/models/groups.php
- */
- <?php
- class Group extends AppModel {
- var $name = 'Group';
- 'User' =>
- 'joinTable' => 'groups_users',
- 'foreignKey' => 'user_id',
- 'associationForeignKey' => 'group_id',
- 'conditions' => '',
- 'order' => '',
- 'limit' => '',
- 'uniq' => true,
- 'finderQuery' => '',
- 'deleteQuery' => '',
- 'insertQuery' => ''
- )
- );
- function parentNode()
- {
- if (!$this->id)
- {
- return null;
- }
- $data = $this->read();
- if (!$data['Group']['parent_id'])
- {
- return null;
- }
- else
- {
- return $data['Group']['parent_id'];
- }
- }
- }
- ?>
Parsed in 0.267 seconds, using GeSHi 1.0.7.14