I have a project witch I started without using a module structure in ZF 1 now I need to place a module structure for managing users (makes more sense to me).
My problem the "default" route should try to go with :controller/:action/:id and the module route
should go with :module/:controller/:action/:id the default from ZF 1 is to use the above without the :id
but my "logic" requires the :id field, how can I make this work?
What I've trying came to:
protected function _initModuleAutoload()
{
$modelLoader = new Zend_Application_Module_Autoloader(
array('namespace' => 'DM',
'basePath' => APPLICATION_PATH . '/modules/default')
, array('namespace' => 'UM',
'basePath' => APPLICATION_PATH . '/modules/users')
);
$modelLoader->addResourceType('service', 'services', 'Service');
$modelLoader->addResourceType('serviceplugin', 'services/plugins', 'Service_Plugin');
return $modelLoader;
}
public function _initFrontController()
{
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$route1 = new Zend_Controller_Router_Route(
':module/:controller/:action/:id/',
array(
'id' => '\d+'
, 'module' => 'default'
, 'controller' => 'index'
, 'action' => 'index'
)
);
$router->addRoute('default', $route1);
$front->addModuleDirectory(APPLICATION_PATH . "/modules/");
$front
->registerPlugin(new Far_Access_Plugin_Identity(), 1)
->registerPlugin(new Far_Access_Plugin_Access(), 2)
->throwExceptions(true)
;
return $front;
}
Also tried to create a second route for users instead of default but did not work.
Any ideas? What am I doing wrong?
A help from irc in freenode was given in channel #zftalk when I provided this link.
Bittarman: crash82: add requirements to the id, so it has to be [\d]+
Bittarman: or, just add an instance of Zend_Controller_Router_Route_Module chained to Zend_Controller_Router_Route with just :id in it, with a default set for id like false.
Bittarman: also, _initModuleAutoload, is pointless Bittarman: having your 'default' module in the modules dir, is kinda wrong
Bittarman: and you stop the frontcontroller resource from working by having an _initFrontController
Bittarman: so resources.frontController will no longer work.crash82: hum... So many problems :( , so I can just place the "default" module into the application directory and any other modules can continue to be loaded from the modules / path ?
Bittarman: yes :)
crash82: going to try that Bittarman: and, each module which has a bootstrap, supplies its own module resource loader
Bittarman: so, if you go creating more like that, you end up with two for each module.
Bittarman: you'd be surprised how many people do tht.
Bittarman: s/tht/that/