Giix Errors For Lookup Tables

Hi all,

I’m new to Yii and Giix. No No wait… :)

I have a simple 6 tables:-

user

permission

group

all linked together with lookup tables

user_has_permission

user_has_group

group_has_permission

The lookup tables are purely user_id,permission_id etc.

I’ve un-installed and re-installed giix 3 times now and last time I’ve kept the yii bundle intact (ie:- not remove the framework folder) and I still get the following error on all occasions.


 include(GroupHasPermission.php): failed to open stream: No such file or directory


/var/www/yii-1.1.14/framework/YiiBase.php(427)


415                         {

416                             include($classFile);

417                             if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php')

418                                 throw new CException(Yii::t('yii','Class name "{class}" does not match class file "{file}".', array(

419                                     '{class}'=>$className,

420                                     '{file}'=>$classFile,

421                                 )));

422                             break;

423                         }

424                     }

425                 }

426                 else

427                     include($className.'.php');

428             }

429             else  // class name with namespace in PHP 5.3

430             {

I’ve checked and giix hasn’t automatically created the lookups (I don’t want the lookups to be models as well). But I created the lookups as models anyways and get another error unrelated to this.

I’ve chowned the whole webroot to www-data before trying to generate User, Permission and Group, just incase it wasn’t being written somewhere else.

Anyways, would love to hear from someone who might know what I’m doing wrong

Thanx again

Replicates on live server as well which is running nginx.

I’m obviously doing something wrong in my setup, though I’ve re-read it 4 times now.

Cause I’m new, I’ve been following the yiibook letter by letter. I’m a bit perplexed now, hopefully this is a silly mistake.

Cheers

And of course it all works fine with just gii though it has nothing to do with lookup tables. Rather it’s not expecting a lookup table called GroupHasPermission.php

Ohh here’s the config. No errors being displayed either.


 // autoloading model and component classes

        'import'=>array(

                'application.models.*',

                'application.components.*',

                'ext.giix-components.*', // giix components

        ),


        'modules'=>array(

                // uncomment the following to enable the Gii tool


                'gii'=>array(

                        'class'=>'system.gii.GiiModule',

                        'generatorPaths' => array(

                                'ext.giix-core', // giix generators

                        ),

                        'password'=>'xxxx',

                        // If removed, Gii defaults to localhost only. Edit carefully to taste.

                        'ipFilters'=>array('127.0.0.1','::1'),

                ),


        ),

        'components'=>array(


                'db'=>array(

                        'connectionString' => 'mysql:host=localhost;dbname=xxxx',

                        'emulatePrepare' => true,

                        'username' => 'xxxx',

                        'password' => 'xxxx',

                        'charset' => 'utf8',

                ),

                'log'=>array(

                        'class'=>'CLogRouter',

                        'routes'=>array(

                                array(

                                        'class'=>'CFileLogRoute',

                                        'levels'=>'error, warning',

                                ),

                                // uncomment the following to show log messages on web pages


                                array(

                                        'class'=>'CWebLogRoute',

                                ),


                        ),

                ),


        ),




Hi, please post the SQL for your tables.

Thanx Rodrigo,

Could be only thing left :)


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,ALLOW_INVALID_DATES';


CREATE SCHEMA IF NOT EXISTS `xxxx` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;

CREATE SCHEMA IF NOT EXISTS `xxxx` DEFAULT CHARACTER SET utf8 ;

USE `xxxx` ;


-- -----------------------------------------------------

-- Table `xxxx`.`user`

-- -----------------------------------------------------

DROP TABLE IF EXISTS `xxxx`.`user` ;


CREATE TABLE IF NOT EXISTS `xxxx`.`user` (

  `id` INT(11) UNSIGNED NOT NULL,

  `username` VARCHAR(16) NOT NULL,

  `email` VARCHAR(255) NOT NULL,

  `password` VARCHAR(64) NOT NULL,

  `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

  `update_time` DATETIME NULL DEFAULT NULL,

  PRIMARY KEY (`id`),

  UNIQUE INDEX `username_UNIQUE` (`username` ASC),

  UNIQUE INDEX `email_UNIQUE` (`email` ASC))

ENGINE = InnoDB;




-- -----------------------------------------------------

-- Table `xxxx`.`group`

-- -----------------------------------------------------

DROP TABLE IF EXISTS `xxxx`.`group` ;


CREATE TABLE IF NOT EXISTS `xxxx`.`group` (

  `id` INT(2) UNSIGNED NOT NULL,

  `name` VARCHAR(45) NOT NULL,

  PRIMARY KEY (`id`))

ENGINE = InnoDB

AUTO_INCREMENT = 2;




-- -----------------------------------------------------

-- Table `xxxx`.`permission`

-- -----------------------------------------------------

DROP TABLE IF EXISTS `xxxx`.`permission` ;


CREATE TABLE IF NOT EXISTS `xxxx`.`permission` (

  `id` INT(2) UNSIGNED NOT NULL,

  `name` VARCHAR(45) NOT NULL,

  PRIMARY KEY (`id`),

  UNIQUE INDEX `name_UNIQUE` (`name` ASC))

ENGINE = InnoDB

AUTO_INCREMENT = 2;




-- -----------------------------------------------------

-- Table `xxxx`.`group_has_permission`

-- -----------------------------------------------------

DROP TABLE IF EXISTS `xxxx`.`group_has_permission` ;


CREATE TABLE IF NOT EXISTS `xxxx`.`group_has_permission` (

  `group_id` INT(2) UNSIGNED NOT NULL,

  `permission_id` INT(2) UNSIGNED NOT NULL,

  INDEX `fk_group_has_permission_group1_idx` (`group_id` ASC),

  INDEX `fk_group_has_permission_permission1_idx` (`permission_id` ASC),

  CONSTRAINT `fk_group_has_permission_group1`

    FOREIGN KEY (`group_id`)

    REFERENCES `xxxx`.`group` (`id`)

    ON DELETE NO ACTION

    ON UPDATE NO ACTION,

  CONSTRAINT `fk_group_has_permission_permission1`

    FOREIGN KEY (`permission_id`)

    REFERENCES `xxxx`.`permission` (`id`)

    ON DELETE NO ACTION

    ON UPDATE NO ACTION)

ENGINE = InnoDB;




-- -----------------------------------------------------

-- Table `xxxx`.`user_has_group`

-- -----------------------------------------------------

DROP TABLE IF EXISTS `xxxx`.`user_has_group` ;


CREATE TABLE IF NOT EXISTS `xxxx`.`user_has_group` (

  `user_id` INT(11) UNSIGNED NOT NULL,

  `group_id` INT(2) UNSIGNED NOT NULL,

  INDEX `fk_user_has_group_user1_idx` (`user_id` ASC),

  INDEX `fk_user_has_group_group1_idx` (`group_id` ASC),

  PRIMARY KEY (`user_id`, `group_id`),

  CONSTRAINT `fk_user_has_group_user1`

    FOREIGN KEY (`user_id`)

    REFERENCES `xxxx`.`user` (`id`)

    ON DELETE NO ACTION

    ON UPDATE NO ACTION,

  CONSTRAINT `fk_user_has_group_group1`

    FOREIGN KEY (`group_id`)

    REFERENCES `xxxx`.`group` (`id`)

    ON DELETE NO ACTION

    ON UPDATE NO ACTION)

ENGINE = InnoDB;




-- -----------------------------------------------------

-- Table `xxxx`.`user_has_permission`

-- -----------------------------------------------------

DROP TABLE IF EXISTS `xxxx`.`user_has_permission` ;


CREATE TABLE IF NOT EXISTS `xxxx`.`user_has_permission` (

  `user_id` INT(11) UNSIGNED NOT NULL,

  `permission_id` INT(2) UNSIGNED NOT NULL,

  INDEX `fk_user_has_permission_user_idx` (`user_id` ASC),

  INDEX `fk_user_has_permission_permission1_idx` (`permission_id` ASC),

  CONSTRAINT `fk_user_has_permission_user`

    FOREIGN KEY (`user_id`)

    REFERENCES `xxxx`.`user` (`id`)

    ON DELETE NO ACTION

    ON UPDATE NO ACTION,

  CONSTRAINT `fk_user_has_permission_permission1`

    FOREIGN KEY (`permission_id`)

    REFERENCES `xxxx`.`permission` (`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;



Got it!! Thanx again Rodrigo.

user_has_permission and group_has_permission, while bundled together and with indexes, they didn’t have those 2 set as a primary key.

I added those as a composite primary key and all seems to be working just fine :)

Cheers again mate

The composite primary key for the table "user_has_permission" is missing. Please update it and try again.

Whoops beat me to it :) Thanx again Rodrigo, now I can really get into the guts.

Serves my right for editing my original before looking here.

Quick question, I do ALL the models first before doing any of the crud?

I usually do. Just enter an asterisk and all models will be generated.

Hi Rodrigo,

I’m still getting exactly the same error now as before. Only when creating or updating a record.

Here’s the current sql followed by the error I’m getting.




-- phpMyAdmin SQL Dump

-- version 4.0.4.1

-- http://www.phpmyadmin.net

--

-- Host: 127.0.0.1

-- Generation Time: Sep 15, 2013 at 05:28 AM

-- Server version: 5.5.32

-- PHP Version: 5.4.16


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

SET time_zone = "+00:00";


--

-- Database: `xxxx`

--

CREATE DATABASE IF NOT EXISTS `xxxx` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

USE `xxxx`;


-- --------------------------------------------------------


--

-- Table structure for table `group`

--


CREATE TABLE IF NOT EXISTS `group` (

  `id` int(2) unsigned NOT NULL,

  `name` varchar(45) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- --------------------------------------------------------


--

-- Table structure for table `group_has_permission`

--


CREATE TABLE IF NOT EXISTS `group_has_permission` (

  `group_id` int(2) unsigned NOT NULL,

  `permission_id` int(2) unsigned NOT NULL,

  PRIMARY KEY (`group_id`,`permission_id`),

  KEY `fk_group_has_permission_group1_idx` (`group_id`),

  KEY `fk_group_has_permission_permission1_idx` (`permission_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;


--

-- RELATIONS FOR TABLE `group_has_permission`:

--   `group_id`

--       `group` -> `id`

--   `permission_id`

--       `permission` -> `id`

--


-- --------------------------------------------------------


--

-- Table structure for table `permission`

--


CREATE TABLE IF NOT EXISTS `permission` (

  `id` int(2) unsigned NOT NULL,

  `name` varchar(45) NOT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name_UNIQUE` (`name`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- --------------------------------------------------------


--

-- Table structure for table `user`

--


CREATE TABLE IF NOT EXISTS `user` (

  `id` int(11) unsigned NOT NULL,

  `username` varchar(16) NOT NULL,

  `email` varchar(255) NOT NULL,

  `password` varchar(64) NOT NULL,

  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

  `update_time` datetime DEFAULT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `username_UNIQUE` (`username`),

  UNIQUE KEY `email_UNIQUE` (`email`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- --------------------------------------------------------


--

-- Table structure for table `user_has_group`

--


CREATE TABLE IF NOT EXISTS `user_has_group` (

  `user_id` int(11) unsigned NOT NULL,

  `group_id` int(2) unsigned NOT NULL,

  PRIMARY KEY (`user_id`,`group_id`),

  KEY `fk_user_has_group_user1_idx` (`user_id`),

  KEY `fk_user_has_group_group1_idx` (`group_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;


--

-- RELATIONS FOR TABLE `user_has_group`:

--   `user_id`

--       `user` -> `id`

--   `group_id`

--       `group` -> `id`

--


-- --------------------------------------------------------


--

-- Table structure for table `user_has_permission`

--


CREATE TABLE IF NOT EXISTS `user_has_permission` (

  `user_id` int(11) unsigned NOT NULL,

  `permission_id` int(2) unsigned NOT NULL,

  PRIMARY KEY (`user_id`,`permission_id`),

  KEY `fk_user_has_permission_user_idx` (`user_id`),

  KEY `fk_user_has_permission_permission1_idx` (`permission_id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;


--

-- RELATIONS FOR TABLE `user_has_permission`:

--   `permission_id`

--       `permission` -> `id`

--   `user_id`

--       `user` -> `id`

--


--

-- Constraints for dumped tables

--


--

-- Constraints for table `group_has_permission`

--

ALTER TABLE `group_has_permission`

  ADD CONSTRAINT `fk_group_has_permission_group1` FOREIGN KEY (`group_id`) REFERENCES `group` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,

  ADD CONSTRAINT `fk_group_has_permission_permission1` FOREIGN KEY (`permission_id`) REFERENCES `permission` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;


--

-- Constraints for table `user_has_group`

--

ALTER TABLE `user_has_group`

  ADD CONSTRAINT `fk_user_has_group_user1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,

  ADD CONSTRAINT `fk_user_has_group_group1` FOREIGN KEY (`group_id`) REFERENCES `group` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;


--

-- Constraints for table `user_has_permission`

--

ALTER TABLE `user_has_permission`

  ADD CONSTRAINT `fk_user_has_permission_permission1` FOREIGN KEY (`permission_id`) REFERENCES `permission` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,

  ADD CONSTRAINT `fk_user_has_permission_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;




Error:-




 include(UserHasGroup.php): failed to open stream: No such file or directory


D:\xampp\htdocs\yii1114\framework\YiiBase.php(427)


415                         {

416                             include($classFile);

417                             if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php')

418                                 throw new CException(Yii::t('yii','Class name "{class}" does not match class file "{file}".', array(

419                                     '{class}'=>$className,

420                                     '{file}'=>$classFile,

421                                 )));

422                             break;

423                         }

424                     }

425                 }

426                 else

427                     include($className.'.php');

428             }

429             else  // class name with namespace in PHP 5.3

430             {

431                 $namespace=str_replace('\\','.',ltrim($className,'\\'));

432                 if(($path=self::getPathOfAlias($namespace))!==false)

433                     include($path.'.php');

434                 else

435                     return false;

436             }

437             return class_exists($className,false) || interface_exists($className,false);

438         }

439         return true;




Again this is only when I try and Create/Update.

Creating User the file it’s looking for is UserHasGroup.php

Creating Group:- GroupHasPermission.php

Creating Permission:- GroupHasPermission.php

It’s got to be a problem with the sql somehow yes?

Hope this makes sense.

Thanx again

Could this have anything to do with my problems?

Yii Issues