On Nov 18, 2010, at 9:20 AM, Fozzyuw wrote:
The Zend_Db reference guide gives an example of "Bugs". You have a
"Bugs"
tables and they create a class called "Bugs" that extends the
Zend_Db_Table_Abstract class.
My first question is, is this a Model? Would it then be stored in the
standard directory "/application/models/"?
When I wrote the documentation for Zend_Db_Table, I took special care
*not* to use the word Model. A data access class is not a Model.
The MVC architecture you have Controllers which handle the request
input at least to decide which Models and Views to invoke; you have
Views which output results from Models; and the Model is where the
bulk of your application-specific business logic lives.
Database access is one thing that the internals of a Model can do.
It's often true that a Model looks up data in the database and
persists new or changed data in the database. But that's an internal
implementation detail of a Model. The Model HAS-A data access class
-- not IS-A data access class.
That said, you have a good question about where do your Table classes
live in your directory structure. The MVC guide does not distinguish
between true Model classes and Table (data access) classes. They all
live under /application/models/ for some reason (many other frameworks
make a similar assumption).
It's as though the /models/ directory is just a place for "everything
that is not a Controller nor a View."
Another option would be to create another directory for other
classes. Suppose you wrote a custom Zend_Log_Writer or something.
That class is clearly not a Model, even though it may be used by some
of your Models. Does it belong under /models/? I think not.
So is the Zend_Db_Table reference simply written for brevity and
they sort
of skip the step of how to connect it to Zend Autoloader and assume
that you
load the class manually in the controller before hand?
Right, I did not address class loading when I wrote the reference docs
for Zend_Db_Table. It's assumed that you're handling classloading in
whatever way you choose to do it, whether you use
Zend_Loader_Autoloader, or explicitly using 'require_once', or a
classmap, or bundling all your classes together into a single file, or
whatever. In any case, none of those methods have anything to do with
the Zend_Db_Table interface, so they don't get documented in that page
of the manual.
I don't have a recommendation at this time for any One True Way of
autoloading classes - either Models or Tables.
Regards,
Bill Karwin