Modeling is not a silver bullet, and as such, the organization of the files can vary depending on how complex or simple your models are. This is exactly why the Model Autoloader can accept new rules, so that your application layer code can be organized in the best possible way, while being able to take advantage of the application layer autoloader.

If you find the primary API for interacting with your models is your actual model file, the secondary API that the models consume is the mapper files, and the other secondary API that models & mappers interact with is your DbTable files, I think it makes a lot of sense to put your mappers inside their own directory for better organization.

The primary purpose behind this organization is that your primary API (consumed by scripts, controllers and view) should be relatively up-front, and secondary API's can be a little deeper, one more pseudo-namespace down as well as one more directory down.

As your project starts to grow, having your mappers in their own place will make it easier for you to both find and conceptualize what code does what.

-ralph

Ali wrote:
Hi Vince42

I am using the same structure for my project, I agree with your suggestion and makes sense to keep a separate folder for mapper files.

I reckon you can do it easily in your Bootstrap.php with something like

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

   protected function _initAutoLoad() {
       $moduleLoader = new Zend_Application_Module_Autoloader(array(
           'namespace'=>'',
           'basePath'=>APPLICATION_PATH
       ));

$moduleLoader->addResourceType('mapper', 'models/mapper', 'Model_Mapper');
             return $moduleLoader;
   }

}

It would make it easier to find mapper files.

I would wait for Matthew's comments.

Thanks

Ali



Vince42 wrote:
Hi,

I just wondered, which is the exact reason for naming / organizing the
three components for data abstraction like it is done in the quickstart.

While it seems perfectly clear that the model is named Guestbook, I find
it a little bit irritating that the Mapper / Gateway is named
accordingly and the DbTable has its own subdirectory.

I think we should either aim for a flat hierarchy like

   Guestbook.php
   GuestbookMapper.php
   GuestbookDbTable.php

or should spend the mappers a directory too - just so that on every
level only files of the same type are accessible ... something like

   Guestbook.php
   Mapper
   --- Guestbook.php
   DbTable
   --- Guestbook.php

I am aware of the fact that you can implement this according to your
personal likes, but I guess - taken into consideration that there's not
always a DbTable to extend - a more general naming convention could keep
irritation low ...

Just my two cents.



Reply via email to