(on Monday, 26 October 2009, 11:48 AM -0700):
> I am developing a website, which also has an admin site. Both of these are
> effectively different sites, or at least in terms of Zend MVC, seperate
> public directories. I need both sites to use the same model (as the
> databases are the same, I would be duplicating a lot of the code if I coded
> them seperately), and the same config file.
>
> What's the easiest way to do this? I know it's easy to create modules to use
> seperate controllers, views and models but they use a common public
> directory. I thought of just putting the model and config folders outside of
> both but this just feels a bit messy.
With Zend_Application and resource autoloaders, this is trivially easy.
Each module should have a Bootstrap.php file containing a class
<ModuleName>_Bootstrap that extends Zend_Application_Module_Bootstrap.
This will automatically create a Zend_Application_Module_Autoloader
instance bound to that module, which gives you the following mappings:
admin/
forms/ Admin_Form_*
models/ Admin_Model_*
services/ Admin_Service_*
views/filters/ Admin_View_Filter_*
views/helpers/ Admin_View_Helper_*
Since all module bootstraps are executed on each request, this means
autoloading for each module is defined up front -- and that means
accessing your models is as simple as simply instantiating them:
class Admin_BlogController extends Zend_Controller_Action
{
public function createEntryAction()
{
$model = new Blog_Model_Entry();
// ...
}
}
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论