Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2008, 08:44 AM
Junior Member
 
Join Date: Aug 2007
Posts: 6
Default how to work with controllers in subdirectories

Hello,

I'm a beginner with zf, and I'm trying now to create some controllers in different directorys.

I created an IndexController into the directory /application/backend/controllers/cars. But I don't know how to reach the controller.

I know that it will work fine, if I will create an CarController.php into the directory /application/backend/controllers.

But because I want to create many Controllers, I would like to seperate them in different directorys.

Is there a good way to organize the controllers, and how can I do this?
And how can I call the controllers in subdirectorys?

/application/backend/controllers
AuthController.php
ErrorController.php
IndexController.php

/application/backend/controllers/cars
IndexController.php

/application/backend/index.php
PHP Code:
set_include_path('.' PATH_SEPARATOR '../../library' PATH_SEPARATOR '../../application/backend/models/' PATH_SEPARATOR get_include_path());
require_once 
'Zend/Controller/Front.php';
.
.
.
/**
 * Setup controller
 */
$frontController Zend_Controller_Front::getInstance();
$controller Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('../../application/backend/controllers');
$controller->throwExceptions(true); // should be turned on in development time 
Thanks for help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-18-2008, 07:42 PM
Junior Member
 
Join Date: Feb 2008
Posts: 1
Default

Try with adding new controller directory:

PHP Code:
$controller->addControllerDirectory('/path/to/controllers'); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-03-2008, 12:58 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default

Quote:
Originally Posted by danield View Post
Hello,

I'm a beginner with zf, and I'm trying now to create some controllers in different directorys.

I created an IndexController into the directory /application/backend/controllers/cars. But I don't know how to reach the controller.

I know that it will work fine, if I will create an CarController.php into the directory /application/backend/controllers.

But because I want to create many Controllers, I would like to seperate them in different directorys.

Is there a good way to organize the controllers, and how can I do this?
And how can I call the controllers in subdirectorys?

/application/backend/controllers
AuthController.php
ErrorController.php
IndexController.php

/application/backend/controllers/cars
IndexController.php

/application/backend/index.php
PHP Code:
set_include_path('.' PATH_SEPARATOR '../../library' PATH_SEPARATOR '../../application/backend/models/' PATH_SEPARATOR get_include_path());
require_once 
'Zend/Controller/Front.php';
.
.
.
/**
 * Setup controller
 */
$frontController Zend_Controller_Front::getInstance();
$controller Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('../../application/backend/controllers');
$controller->throwExceptions(true); // should be turned on in development time 
Thanks for help!
The manual has a good section on this (section 7.11). So if you do not understand my reply, please consult the manual.

If you have a module other than the default one and want to set the path to its controller, you can call:
PHP Code:
$controller->addControllerDirectory('path_to_cars_controllers','cars'); 
The index controller for cars should be called Cars_IndexController, so it has to be prefixed with the module name.

Do NOT prefix the filename of the Cars_IndexController, it should be called IndexController.php!

An easy way to avoid have to add directories for all of your modules is to ditch all of the calls to setControllerDirectory (yes, all of them) and to just call:
$controller->addModuleDirectory('your_application_root'); This will work if you use the default directory structure, with all your modules located under the application root, like in myapps/admin, myapps/default, myapps/cars etc.

Bart McLeod

Last edited by mcleod@spaceweb.nl : 03-03-2008 at 09:43 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:07 PM.