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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-26-2008, 06:54 AM
Junior Member
 
Join Date: Jan 2008
Posts: 3
Default Routing to Modules

Hi, I'm having a lot of trouble routing requests to modules.

I've set up an XML config file containing my routes (below), and I load it into the router in my bootstrap (also below).

I have two routes: a default route, which just goes to Default/IndexController->indexAction, and a projects route, which is supposed to go to Projects/Project_IndexController->indexAction.
(I'm using Default/ and Projects/ here to signify modules)

The problem is, I can't browse to url/projects - I just get taken to the default controller.

My front controller is successfully loading the paths for each of these modules (also in an XML file), so that is not an issue.

I've tried reversing the order of my routes, just in case, but without success.

Setting the module property of the default route to "projects" successfully redirects to the project controller.

What is going on?

routes.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<routes>
  <production>
  </production>
  
  <staging extends="production">
    <routes>

      <default>
        <route></route>
        <defaults>
        	<module>default</module>
        	<controller>index</controller>
        	<action>index</action>
        </defaults>
      </default>
      
      <projects_index>
        <route>projects/</route>
        <defaults>
        	<module>projects</module>
        	<controller>index</controller>
        	<action>index</action>
        </defaults>
      </projects_index>

    </routes>
  </staging>
</routes>

Bootstrap: (index.php)
PHP Code:
// Routes
$routes = new Zend_Config_Xml('../site/config/routes.xml''staging'true);

// Get the front controller
$front_controller Zend_Controller_Front::getInstance();

// Get the router
$router $front_controller->getRouter();

// Load the site routes into the router
$router->addConfig($routes'routes');

// Display the site
$front_controller->dispatch(); 
This is the output of var_dump( Zend_Controller_Front::getInstance()->getRouter()->getRoutes() ):

Code:
array(2) {
  ["default"]=>
  object(Zend_Controller_Router_Route)#19 (11) {
    ["_urlVariable:protected"]=>
    string(1) ":"
    ["_urlDelimiter:protected"]=>
    string(1) "/"
    ["_regexDelimiter:protected"]=>
    string(1) "#"
    ["_defaultRegex:protected"]=>
    NULL
    ["_parts:protected"]=>
    NULL
    ["_defaults:protected"]=>
    array(3) {
      ["module"]=>
      string(7) "default"
      ["controller"]=>
      string(5) "index"
      ["action"]=>
      string(5) "index"
    }
    ["_requirements:protected"]=>
    array(0) {
    }
    ["_staticCount:protected"]=>
    int(0)
    ["_vars:protected"]=>
    array(0) {
    }
    ["_params:protected"]=>
    array(0) {
    }
    ["_values:protected"]=>
    array(0) {
    }
  }
  ["projects_index"]=>
  object(Zend_Controller_Router_Route)#15 (11) {
    ["_urlVariable:protected"]=>
    string(1) ":"
    ["_urlDelimiter:protected"]=>
    string(1) "/"
    ["_regexDelimiter:protected"]=>
    string(1) "#"
    ["_defaultRegex:protected"]=>
    NULL
    ["_parts:protected"]=>
    array(1) {
      [0]=>
      array(1) {
        ["regex"]=>
        string(8) "projects"
      }
    }
    ["_defaults:protected"]=>
    array(3) {
      ["module"]=>
      string(8) "projects"
      ["controller"]=>
      string(5) "index"
      ["action"]=>
      string(5) "index"
    }
    ["_requirements:protected"]=>
    array(0) {
    }
    ["_staticCount:protected"]=>
    int(1)
    ["_vars:protected"]=>
    array(0) {
    }
    ["_params:protected"]=>
    array(0) {
    }
    ["_values:protected"]=>
    array(0) {
    }
  }
}
Thanks in advance,
Will.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-27-2008, 08:31 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

Both of the routes you set are messing up the routing process. There is a 'default' route in the router by default which should not be overridden unless you are hacking the router

By default ZF will route to the url's you specified. /<moduleName> / -> default/index/index
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-27-2008, 01:46 PM
Junior Member
 
Join Date: Jan 2008
Posts: 3
Default

Ok, fair point. I removed the 'default' entry from routes.xml, but even when I browse to url/projects/index/index I still get routed to the default module.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-27-2008, 09:28 PM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

Strange.... you do have mod_rewrite setup right?
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-28-2008, 02:12 PM
Junior Member
 
Join Date: Jan 2008
Posts: 3
Default

Yeah, mod_rewrite is ok. As I said, changing the default rule to route to the projects module works fine, the project controller gets focus and everything is good. It's just the other route that refuses to work.
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 07:58 AM.