[Solved] Zend Framework Data-Mapper Question

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

[Solved] Zend Framework Data-Mapper Question

Post by DaveTheAve »

So I'm trying to make the datamapper: Application_Model_UserMapper work as Application_Model_Mapper_User to make things look A LOT cleaner... I moved the UserMapper.php into "application/models/Mapper" and called it User.php and changed all the calls to Application_Model_Mapper_User and i still get "Fatal error: Class 'Application_Model_Mapper_Users' not found in /var/www/xxxxxx/application/controllers/IndexController.php on line 13"


So what should I do now? I thought the Zend_Loader was supposed to handle loading this file automaticly by the naming convention?

P.S.... This isn't my first ZF project but it's the first time I'm using it with a Data Mapper and I just started the project.... I'm liking the DM way of things though. :P

P.S. 2.0: I hate to start a new topic on this, but I need to know: I'm thinking about using the ZF Modules ability creating a default and admin module. If I define all the DbTables, Models, and Mappers in the default model, can they be accessed in the admin module or do I need to copy and paste them into the admin module?
Last edited by DaveTheAve on Mon May 03, 2010 12:32 am, edited 1 time in total.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Zend Framework Data-Mapper Question

Post by Darhazer »

The UserMapper should be in application/models/
So if you call class Application_Model_UserMappe, it will try to load application/model/UserMapper.php
Actually the _ in the class name is the directory separator, in the default Zend Autoloader.
And Application_Model_Mapper_Users should be defined in /application/model/mapper/Users.php
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Re: Zend Framework Data-Mapper Question

Post by DaveTheAve »

I understand that the "_" is the directory separator but if call "Application_Model_Mapper_Users", "/application/model/Mapper/Users.php" is NOT being called... and yes Application_Model_Mapper_Users IS defined in Users.php.
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Re: Zend Framework Data-Mapper Question

Post by DaveTheAve »

Fixed it... ended up being a "feature" of Zend Framework.

My fix was to add this code into the bootstrap.php file:

Code: Select all

    protected function _initAutoloaders()
    {
        $loader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Application',
        'basePath' => APPLICATION_PATH
        ));
        $loader->addResourceType ( 'mapper', 'models/Mapper', 'Model_Mapper'); 
        return $loader;
    }
Post Reply