0

I'm working with multi-modules CMS in Zend Framework. I want to create a structure like this:

testsite/
index.php
library/
    zend/
    test/
application/
    configs/
        application.ini
    modules/
        users/
            controllers/
            models/
        ....
    frontend/
        controllers/
        models/
        ....
    backend/
        controllers/
        models/
        ...
    bootstrap.php

I have created the following code:

//in application.ini
resources.frontController.defaultModule = "frontend"
resources.frontController.defaultControllerName = "index"
resources.frontController.defaultAction = "index"
resources.frontController.plugins.init = "Test_Controller_Plugin_Initializer"

//in bootstrap.php
 protected function _initControllers()
{
    $this->bootstrap('frontController');
    $this->_front = $this->getResource('frontController');

    $this->_front->addControllerDirectory(APPLICATION_PATH . '/backend/controllers', 'backend');
    $this->_front->addControllerDirectory(APPLICATION_PATH . '/frontend/controllers', 'frontend');
}

 //in Test/controllers/plugin/initializer.php
 public function preDispatch(Zend_Controller_Request_Abstract $request)
{          
    $front = Zend_Controller_Front::getInstance();
    $request = $front->getRequest();

    $request->setModuleName('frontend');
    $request->setControllerName('index');
    $request->setActionName('index');
}

It does not work when I go to my base URL .../testsite. Can you please let me know where I went wrong?

Jonas G. Drange
  • 8,749
  • 2
  • 27
  • 38
  • show what u have in .htaccess file – Raj Dec 17 '12 at 18:20
  • in my .htaccess, i have code like this: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] – user1910548 Dec 18 '12 at 16:41
  • It looks like you have a security problem. Index.php in the `/testsite/` directory which makes everything in your application potentially servable. Not a good Idea. you should at least implement a public or html directory and put your application outside of your docroot. – RockyFord Dec 22 '12 at 13:35

2 Answers2

0

Have you tried putting your modules in the modules directory? ie:

testsite/
index.php
library/
    zend/
    test/
application/
    configs/
        application.ini
    modules/
        users/
            controllers/
            models/
        ....
        frontend/
            controllers/
            models/
            ....
        backend/
            controllers/
            models/
            ...
    bootstrap.php

Wich is typically where zf expects to find its modules. You might have to adjust you rapplication.ini settings to reflect this.

Iznogood
  • 12,447
  • 3
  • 26
  • 44
0

To make this work how you want it to refer to Zend_Application_Resource_Frontcontroller

specifically you need to pass an array of 'module' => 'controller' directory pairs to resources.frontController.controllerDirectory.

controllerDirectory: either a string value specifying a single controller directory, or an array of module to controller directory pairs.

I doubt this will solve all the problems but it should head you in the right direction.

RockyFord
  • 8,529
  • 1
  • 15
  • 21