I am currently extending my model component and would be interested in
your feedback.
The component currently is split into five classes though i dont know
if i realize point 5:
1. Model Loader
2. Model Adapater
3. Model Names
4. Model Abstract
(5. Model Validator)
Every component can be used on its own.
1. Model Loader
This component loads the models ;). It offers three ways to load a model:
Load by exact path, load by classname and load model from specified
directory stack.
* Load by path:
// path, modelclassname
$modelLoader->loadByPath('funkymodels/ohyeah/disostu.php', 'Model_DiscoStu');
* Load by classname:
// modelclassname
$modelLoader->loadByName('App_Models_DiscoStu');
* Load by directory stack:
// modelclassname
$modelLoader->load('DiscoStu');
This option will mostly be used in MVC mode.
1.2 Model loader MVC
The model loader contains a MVC mode.
When activated the model loader controller helper gets registered,
which simply allows you to load models from your controllers etc.
When loaded, the helper auto detects the current modulepath and adds
the model directory to the loader stack, so you dont have to bother
yourself with adding it.
The MVC mode expects the models to be stored in a models directory
which is a subdir of the current module, like controllers.
Example: /htdocs/application/modules/<module>/models/
2. Model Adapter
This component is basicly a registry for adapaters like Zend_Db or
whatever you use. It only consists of two static methods, addAdapater
and getAdapter.
This class makes it possible to add, get or exchange different
adapaters wherever and whenever you want.
(Setup your adapaters where also the basic app configuration is occuring)
I dont want to use Zend_Registry because it can contain everything, i
cant controll the access to the saved apadaters and it would create an
unneccesary dependecy.
3. Model Names
Enables the option to add tablenames bound to a namespace in a
centeral place (like adapaters) and retrieve those everywhere you
want, most logical in your models.
So you can simply exchange or modify tablenames without editing N files.
4. Model Abstract
An abstract class which provides wraper methods for the classes
adapater and names. Every model which extends this class gains the
vantages of those two classes.
Basicly you dont have to bother with anything when using this abstract
class as your base.
5. Model Validator
Basicly a Zend_Filter_Validator managment class. Setup the basic
stuff, offer a validate method which awaits a validator array and data
to validate and error handling managment (Throw Exception, safe errors
etc).
Model abstract would also offer wraper methods for this class.
The component directory structure:
+- library
+- <mylib>
+- Model
+- Adapter
- Exception.php
+- Loader
- Exception.php
- ControllerHelper.php
- Abstract.php
- Adapater.php
- Exception.php
- Loader.php
- Names.php
- Validator.php
Regards
Ota