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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-05-2007, 09:15 PM
Junior Member
 
Join Date: Sep 2007
Posts: 1
Default Multiple routes and strange View behaviour

I have a multiple routes in my front controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory(array(
'default' => dirname(__FILE__) .'/application/controllers/default/',
'admin' => dirname(__FILE__) .'/application/controllers/admin/',
'user' => dirname(__FILE__) .'/application/controllers/user/',
'error' => dirname(__FILE__) .'/application/controllers/error/'
));
in that case if i write http://localhost/admin/
its loading the controller from the application/controllers/admin/ directory
and that is normal but view is loading always form the /var/www/html/application/controllers/views/scripts/
In that case i can not have a different templates for the diferent routes.

That loooks realy strange. Obviously i miss something in general.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-12-2008, 03:46 AM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default Same problem

I'm having the same problem. I haven't been able to figure out where/how to set a module-specific view directory. The default module works fine, but it seems like there must be a way to configure my app so I can place my view files somewhere like this:

./application/views/scripts/admin/index/index.phtml

and not this seemingly ambiguous location:

./application/controllers/views/scripts/index/index.phtml

Any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-12-2008, 02:23 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

Your view scripts should be stored in a folder scheme similiar to this:

....../view/scripts/controller/action.phtml

But instead of loading each controller individually, Why not use the Auto Loader?

PHP Code:
    // Register the autoloader
    
require_once 'Zend/Loader.php';
    
Zend_Loader::registerAutoload(); 
More info here: Zend Framework: Documentation: Zend_Loader
__________________
- xentek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-12-2008, 02:43 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default

I'm not sure how Zend_Loader applies. My controllers are already loading properly, my problem is that I don't know how to change where ZF is looking for my views.

If you happen to have multiple modules that have the same controller names, what happens? Using 'admin' and 'public' as modules, here's an example:

http://site/admin/user/edit

and

http://site/public/user/edit

Both are going to try to pull the view from:

.../view/scripts/user/edit.phtml

An obvious workaround would be to never use the same name for controllers in different modules, but it seems like there should be a better way to control where views are stored.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-12-2008, 02:44 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

Admin is the name of your controller?
__________________
- xentek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-12-2008, 04:26 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default

No, admin is the name of one of my modules. User is the name of the controller, and edit is the action.

I have defined multiple modules in my bootstrap like this:

PHP Code:
$front Zend_Controller_Front::getInstance();
//$front->setControllerDirectory('../application/controllers');
// configure router to allow for multiple modules
$front->setControllerDirectory(
   array(
       
'default' => '../application/controllers',
       
'admin'   => '../application/controllers/admin',
       
'public'  => '../application/controllers/public'
   
)
); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-12-2008, 04:40 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

Looks like you need to organize the view and models for your modules underneath the module directory.

Take a look at the docs: Zend Framework: Documentation

In your case it would look something like this:

Code:
..../application/admin/controllers/*
..../application/admin/models/*
..../application/admin/views/*

And

..../application/public/controllers/*
..../application/public/models/*
..../application/public/views/*
It must default to the standard location when you don't organize this way, which causing the collision that you are experiencing.
__________________
- xentek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-12-2008, 04:59 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
Default

That does it. Seems that I just had my directories in the wrong sequence. Thank you for your help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-12-2008, 07:46 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

No problem. I'm still learning the Zend Framework, and this an area that we're going to be getting into soon (admin section), so I'm glad I could help you work it out... I'll be doing something similar soon!
__________________
- xentek
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:52 PM.