Lets say that I have a table containing users. Each row in that table is thus a user. The important part here is the plural vs singular form.
Now, let's look at the we set up models for these in Zend Framework:
class Model_Users extends Zend_Db_Table_Abstract
{
protected $_name = 'users';
protected $_primary = 'user_id';
}
Now, let's further presume that we want another user object other than the standard row returned by the Zend_Db_Table
, but we would still like to keep its functionality, just extend it. It would then make sense to implement and name a single user like:
class Model_User extends Zend_Db_Table_Row_Abstract
{
... Bunch of cool functions here :)
}
We then just add
protected $_rowClass = 'Model_User';
to the Model_Users
class and we're done... Normally that would be the case, but there seems to be a problem here in the way Zend Framework auto-loads the classes. Since we can have the folder structure /defaut/models/foo.php
and name the class within that Model_Foo
. The folder has a plural name but the class has a singular one. This seems to become a problem when I want to have the above stated structure. Since Zend Framework doesn't seem to be able to differentiate between the UserModel.php
and UsersModel.php
.
So the question to this long and somewhat poetic question is:
Is there a way to get around this WITHOUT starting to manually use includes?
Actually it is recommended to put your table classes in db folder within models, so it would be models/dbtable/users.php and class name Model_DbTable_Users for table, and models/user.php and Model_User for concrete user. But if you decide to skip on that I don't see the problem of having model/user.php with Model_User and models/users.php with Model_Users as table.