Page 1 of 1

[Solved] Zend Framework Data-Mapper Question

Posted: Sat May 01, 2010 6:54 am
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?

Re: Zend Framework Data-Mapper Question

Posted: Sat May 01, 2010 1:19 pm
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

Re: Zend Framework Data-Mapper Question

Posted: Sat May 01, 2010 3:01 pm
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.

Re: Zend Framework Data-Mapper Question

Posted: Mon May 03, 2010 12:31 am
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;
    }