views:

406

answers:

3

I'm using the default framework code that was created with the Zend Framework Application tool, I added some autoloader magic so that any classes named Default_<*>_<*> would automatically be loaded from the correct directory, in this case Default_Model_TableName.

application/models/ProjectCategories.php:

<?php

class Default_Model_ProjectCategories extends Zend_Db_Table_Abstract {
    protected $_name = 'categories';
    protected $_dependentTables = array('Projects');
}

application/models/Projects.php:

<?php

class Default_Model_Projects extends Zend_Db_Table_Abstract {
    protected $_name = 'projects';

    protected $_referenceMap    = array(
        'Category' => array(
            'columns'           => 'cid',
            'refTableClass'     => 'ProjectCategories',
            'refColumns'        => 'id',
            'onUpdate'          => self::CASCADE,
            'onDelete'          => self::CASCADE,
        )
    );

}

What I am attempting to do is the following:

<?php
$categories = new Default_Model_ProjectCategories();
$category = $categories->find('1');
$category->findProjects();

At which point I get an error thrown at me that it is unable to find Projects.php, and or that the file might not have contained a class named Projects.

At that point I place Projects.php in the include path that was set up by the framework (/../library/) and the file is found, but now I lose my whole directory structure, and naming because I had to rename Default_Model_Projects to Projects. I am able to get everything to work if I place the file back in its original location, and change

protected $_dependentTables = array('Projects');

to

protected $_dependentTables = array('Default_Model_Projects');

but this also means that my ->findProjects() now becomes ->findDefault_Model_Projects().

Is there a way to tell it that when I am looking for findProjects() that it has to instantiate Default_Model_Projects? Is this something that is missing from Zend Framework, or am I attempting to shoehorn something in a way that it does not belong? How have you solved this issue?

+1  A: 

This problem may have been introduced by the new Autoloader, and the way in which it prefers to load namespaced classes (e.g. those prefixed as you have ).

In my applications I simply name models like 'Projects' and add a separate models folder to the include path for that application. This is one solution - unfortunately I don't know how you can make the namespaced models load correctly, but I would suggest looking at Zend_Loader in greater detail, and possible the pluginLoaders.

David Caunt
A: 

Change

protected $_dependentTables = array('Projects');

to

protected $_dependentTables = array('Default_Model_Projects');
Tomáš Fejfar
You apparently did not read my entire question ...
X-Istence
haha, sorry :) I missed that :) You can do this:*public function findProjects(){ $this->findUgly_Long_Name();}*
Tomáš Fejfar
A: 

i used to be able to do something like

$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
    'basePath'  => APPLICATION_PATH,
    'namespace' => 'App',
));
$resourceLoader->addResourceType('model', 'models/', '');

to shrink my model classes to App_TableName but seems like its not working now...

iceangel89