Skip navigation.

Zend_Loader

Hi,

First of all, the Xyster library looks very promising and I already use it with success, thnx.

My question,

How should I handle the loading of models with respect to a module layout. By example: I have a structure like this:

application/news/models/Item.php

application/news/models/ItemSet.php

application/news/models/ItemMapper.php

I add in the controller the include path 'application/news/models'. Loading of Item.php is done by require_once 'Item.php'. I run in problems cause the Xyster/Orm/Loader.php can't handle the loading of the Mapper class.

Is there a workaround or am I missing some alreading existing functionality?

In the example you gave, all

In the example you gave, all that should be necessary for you to use the ORM classes is to pass the full path for application/news/models to Xyster_Orm_Loader::addPath().

After you add the path, when you use the methods on the Xyster_Orm class, Xyster_Orm_Loader will look in all of the paths you have provided for classes to instantiate.

Let's say you have "application/news/models", "application/foobar/modules", and "application/example/modules". Then let's say you pass all three of these paths to Xyster_Orm_Loader::addPath(). Next, you call Xyster_Orm::getInstance()->get('Item', 1). The ORM layer will go through news/modules, foobar/modules, and example/modules looking for 'Item.php'.

Did this answer your question?

I told you not the whole

I told you not the whole truth ;-)

My layout is

/application/models/ /application/modules/news/controllers/ /application/modules/news/models/ /application/modules/foo/models/ etc.

My models are named as file like Item.php but to avoid collision the class name is News_Item. With setting my include path dynamically at module level I can use require_once 'Item.php'. But with this layout I can't use the default Zend_Loader/Xyster_Orm_Loader functionality.

Okay, I see now. Well, under

Okay, I see now.

Well, under a custom naming scheme like that, and if you're using require_once to include all the classes, you shouldn't need to use Xyster_Orm_Loader anyway.

If I were to make your domain model from scratch, I'd try to avoid generic names like "Item" so that your entities can all sit together in one directory.

Is there any reason you can't name the file "News_Item.php", "News_ItemSet.php", etc.? Then you could use the Loader.

User login