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’.
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).
Created a new database table ‘submissions’ that includes an FK referencing user ID.
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’),
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');
Used Giix to generate CRUD for the ‘submissions’ model.
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"
- 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.
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!