duanjing4667 2010-09-13 15:55
浏览 33
已采纳

需要在cakePHP中拥有多个组中的用户

Hello I am trying the ACL component in cakephp for my web application. The example on their website for using their ACL structure has a many to one relationship between groups and users. A user can belong to one group, while a group can have more than one users in it.

But I have a situation where I need to have a few users in more than one group. For that I had to change the table structure, as it would be a many to many. So I built an associative entity called "groups_users". Now I have baked all the controllers, models, and views.

I have added groups and users, and things are working fine. I have also added the components into the parent class, AppController. I have also generated the ACL tables ACOs, AROs and AROs_ACOs using the baking console.

So in the groups_users add view, I have a list of users and groups. I can choose the users and their groups, and on submit a record has to be technically created in my groups_users table.

But to my surprise, records are being inserted into aros_acos table which is weird. I believe there is some internal relation between users, groups and the acl tables. I tried to understand if there was any foreign key cascading between these tables, but nothing was mentioned in the config/schema/dbacl.sql file.

I am pasting my table structure for a better understanding of my problem.

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `acl_cake` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `acl_cake` ;

-- -----------------------------------------------------
-- Table `acl_cake`.`users`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`users` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `username` VARCHAR(255) NOT NULL ,
  `password` CHAR(40) NOT NULL ,
  `created` DATETIME NULL DEFAULT NULL ,
  `modified` DATETIME NULL DEFAULT NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX (`username` ASC) );


-- -----------------------------------------------------
-- Table `acl_cake`.`groups`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`groups` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(100) NOT NULL ,
  `created` DATETIME NULL DEFAULT NULL ,
  `modified` DATETIME NULL DEFAULT NULL ,
  PRIMARY KEY (`id`) );


-- -----------------------------------------------------
-- Table `acl_cake`.`posts`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`posts` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `title` VARCHAR(255) NOT NULL ,
  `body` TEXT NULL DEFAULT NULL ,
  `created` DATETIME NULL DEFAULT NULL ,
  `modified` DATETIME NULL DEFAULT NULL ,
  `user_id` INT(11) NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_posts_users1` (`user_id` ASC) ,
  CONSTRAINT `fk_posts_users1`
    FOREIGN KEY (`user_id` )
    REFERENCES `acl_cake`.`users` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);


-- -----------------------------------------------------
-- Table `acl_cake`.`widgets`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`widgets` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(100) NOT NULL ,
  `part_no` VARCHAR(12) NULL DEFAULT NULL ,
  `quantity` INT(11) NULL DEFAULT NULL ,
  PRIMARY KEY (`id`) );


-- -----------------------------------------------------
-- Table `acl_cake`.`groups_users`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`groups_users` (
  `id` INT NOT NULL ,
  `user_id` INT(11) NOT NULL ,
  `group_id` INT(11) NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_permissions_users` (`user_id` ASC) ,
  INDEX `fk_permissions_groups1` (`group_id` ASC) ,
  CONSTRAINT `fk_permissions_users`
    FOREIGN KEY (`user_id` )
    REFERENCES `acl_cake`.`users` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_permissions_groups1`
    FOREIGN KEY (`group_id` )
    REFERENCES `acl_cake`.`groups` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  • 写回答

2条回答 默认 最新

  • du1068 2010-09-13 19:13
    关注

    This may help get you pointed in the right direction or possibly give you another route to take. Simple Auth Users Has And Belongs To Many Groups CakePHP

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序