0
votes

I am working on implementing Zend Framework within an existing project that has 2 front-ends sites (the company has two sites for two tv chanels) that are administrated by the same backend site. Currently these are poorly organized with two instances of zend framework that duplicate the code of the backend/admin area and duplicate the databases since both site and backend share the data base.

In implementing the Zend Framework, I would like to create be able to split this structure this way: 1 module front-site1, 1 module for front-end site 2 and 1 module for backend/admin site. I need to be able to point each module to the same models since all three modules work on the same database and on the same business objects.

However, I haven't been able to find any information on how to do this in the documentation. Can anyone help with either a link on how to do this or some simple instructions on how to accomplish it? or to come up with a better structure if i am getting this wrong? What kind of configuration should i setup in ZF to make sure that www.site1.com -> module1 (front-end1) and www.site2.com -> module2 (front-end2) and both admin.site1 and admin.site2.com point to module3 (admin/backend)

1
I think your biggest problem is likely to be getting the url's and routing correct (I'm not qualified to help with routing or I would offer suggestions). Using classes between modules is no issue at all I routinely use forms and models between modules. I usually setup my dbTable models in the default model/dbtable directory and share them every where. Just call the correct classname and everything tends to work as expected. As always you still have the library available for code that might not fit elsewhere and needs to be shared. - RockyFord

1 Answers

0
votes

Correct me if i'm wrong, you need to have all "core" and "library" for all models, and 3 different "modules" 1) site1

2) site2

3) admin

If that is correct, you can do the following things.

File Index.PHP Add something like this.

// Define application environment
$environments = array(
    'localhost' => 'local'
    'www.site1.com' => 'site1',
    'www.site2.com' => 'site2',
);

$host = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;

if (isset($environments[$host])) {
    defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : $environments[$host]));
}else{
    defined('APPLICATION_ENV','local');
}

Add all Environments you need and all your sites

File config/application.ini Need to have something like this, with all the rest of the information.

; -----------------------------------------------------------------------
[production]
; -----------------------------------------------------------------------
resources.frontController.moduleDirectory[] = PUBLIC_PATH "/modules"
resources.frontController.plugins.moduleselector = "Your_Application_Plugin_ModuleSelector"
; -----------------------------------------------------------------------
[site1 : production]
; -----------------------------------------------------------------------
settings.module.name = "site1"
; -----------------------------------------------------------------------
[site2 : production]
; -----------------------------------------------------------------------
settings.module.name = "site2"

And create the plugin file.

class Your_Application_Plugin_ModuleSelector extends Zend_Controller_Plugin_Abstract {
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        ...
        $request->setModuleName($getVarFromApp);
    }
...
}

You need to get the module name from the application.ini

then you need to have the folder:

/module/site1

/module/site2

/module/admin

The admin site can access from both site, from the url www.site1.com/admin

Example of controller from ADMIN

<?php
class Admin_IndexController extends Zend_Controller_Action
{

    private $params;

    function init()
    {

    }

    public function indexAction()
    {

    }
}

Example of controller from site1 or site2

<?php
class IndexController extends Zend_Controller_Action
{

    private $params;

    function init()
    {

    }

    public function indexAction()
    {

    }

}

I hope this works, do not check, but basically is the idea of what to do. Any question let me know