Yii Framework Forum: Giix Compatibility With User + Rights - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Giix Compatibility With User + Rights User vs. Users pluralization issue for Giix relations? Rate Topic: -----

#1 User is offline   Cavelle 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 06-February 13

Posted 06 February 2013 - 12:31 PM

Sorry if there is an obvious question, but as Yii noobie I can't figure out what is happening or what to try next. I'm hoping someone can't point me in the right direction.

I generated CRUD with Giix for a new table that references user_id, but when I try to navigate to /submissions, I get an error "include(Users.php): failed to open stream: No such file or directory"

It looks like somewhere someone is assuming that the 'user' model is pluralized, and looks for 'users.php' instead of 'user.php'. The database table by default is indeed called 'users', but the class is singular 'user'.

Exact steps:
1. Using the excellent starting point 'Yii with User + Rights' (github.com/ benjaminlhaas/ Yii-with-Users-and-Rights, updated recently to Yii 1.1.12), MySQL, Linux. Regular CRUD generation worked OK (but never tried any relationships).

2. Created a new database table 'submissions' that includes an FK referencing user ID.

3. Used Giix to create the model. It correctly identified that there was a relationship, as the relations function in the generated model includes the line:
'user' => array(self::BELONGS_TO, 'Users', 'user_id'),

4. Edited the relations in the user module manually to include the other side of the relationship:
if (!isset($relations['submissions']))
$relations['submissions'] = array(self::HAS_MANY, 'Submissions', 'user_id');

5. Used Giix to generate CRUD for the 'submissions' model.

6. Navigated to /submissions, result:
PHP warning on the top of the web page, plus the related stack trace:
"include(Users.php): failed to open stream: No such file or directory"

7. When using Giix to generate CRUD for other new models that have relationships between them, it does a great job, producing drop-down lists that reference the item instead of just the index number. So when Giix handles both ends, things seem to work as expected, the challenge seems to be when combining it with the existing User model.

I've thought of various workarounds, including investigating the pluralization standards for model and database tables in Yii. (The great thing about standards is there are so many to choose from - every possible combination seems to be someone's standard in Yii, even the books and tutorials take different (and equally valid, just incompatible, approahces). It looks like if you pick up other people's extensions, you have to manually change the conventions (undue risk) or just end up with a nice mix of every combination :) The obvious one to me was to change the 'Users' reference in the BaseSubmission model to 'User', but that results in a different error 'User and its behaviors do not have a method or closure named "label".'

Some of the other things I've tried have let the new model CRUD work to the point of displaying data, though it only shows the actual user_id index, never the referenced field data as happens when Yiix generates models/CRUD at both ends of the relationship. I could quit using the User module, but it does exactly what I want (and looks like one of the most-used modules), or I could go back to just Gii and add in what I need manually, but Giix also does what I want with a lot less work.

I'm sure there is something fundamental I am missing about Yii, Yiix, relations, pluralization, and/or User. Any ideas? Thanks for reading.

Best regards,

John

ps Having come from the Drupal world, despite the learning curve with a new system, the fact that Yii is closer to the metal and the database makes me feel I might actually become productive in Yii in a way I couldn't when I was constantly battling with Drupal GUI, modules or custom modules, always fighting just to get to the tables and relations. Thank you to the Yii community for creating something so promising!
0

#2 User is offline   codepress 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-August 12

Posted 07 February 2013 - 06:00 PM

Look at /protected/modules/user/UserModule.php line 95

You can change the name of the user(s) table there. This worked for me.
0

#3 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 09 February 2013 - 07:59 AM

Hi Cavelle,

I have never used the User extension, so I can't contribute.
Please try the fix proposed by codepress and let us know if this works for you.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users