I want to put models outside module directory in Zend Framework. To be precise, in /library folder
library/
models/
actors/
ActorsMapper.php
Actor.php
books/
BooksMapper.php
Book.php
INSTEAD OF
application/
modules/
models/
actors/
ActorsMapper.php
Actor.php
books/
BooksMapper.php
Book.php
This is done so that I don't have to create separate model for each of the module I create. What configurations will I have to change? If you need more details, please ask.
Thank you :)
If you want to use same models for all modules you can put it in application folder applications/models
and that works fine just like when you have web without modules.
But If you want to have models in library, You can put 'models' folder in your library path and autoload it.
In configs/application.ini Put:
Then you can use namespace 'Models_' in your web application
In controller:
in any case, I recommend that you keep the folder models in the path application/models
First answer works, but I will give you another answer in case if you want to register autoload in bootstrap.
1) put 'models' folder into library with all Table.php files.
Every model/class should have:
2) In bootstrap.php put:
That's it. Now you can use your models in controllers like this:
zend autoloader loading class which name beginning with prefix, that is registred on it. If you have library in your include path, you can simple register "Models" like default namespace on autoloader and name your class for example Models_Actors_Actor.