views:

23

answers:

1

Very likely I'm going about this in the wrong way entirely. I'm completely new to the framework..

The site I am developing has two "parts" that are mainly separate. An informational/community half, and a commerce half. I'm using the following directory structure:

--application
----default
------controllers
------layouts
------models
------views
----store
------controllers
------layouts
------models
------views
--config
--library
--public

I would like to have a URL structure when browsing for products as follows:

/view/category/model/revision

This would pull up a specific product/revision - but I would like to back-track as well (browsing all revisions, all models, etc). I can't figure out how to achieve this.. My route is setup like this:

Bootstrap.php

  $front = Zend_Controller_Front::getInstance();
  $router = $front->getRouter();
  $route = new Zend_Controller_Router_Route(
      'view/:cid/:sku/:rev',
      array('module' => 'store', 'controller' => 'index', 'action' => 'index')
  );
  $router->addRoute('view', $route);

This works fine for pulling up a specific product, but throws an exception (it reverts to the default module and complains that the controller 'view' does not exist) when leaving out any of the 3 labeled parameters. Is it possible to put in optional labels, where it would continue to use the view controller under the store module for 1-3 parameters? Am I missing the point?

I found nothing in the framework docs, but I wouldn't be surprised if I just couldn't find the page.. There's something about the Zend Framework documentation that drives me crazy.

Thank You

+3  A: 

I'm not really a ZendFramework guy, but it's obvious the missing parameters are causing the issue. Routes are matched in reverse order. Could it be passing a NULL value to the view when 3 parameters are passed and it is expecting 4?

What if you tried something like:

$route = new Zend_Controller_Router_Route(
      'view/:cid/:sku/:rev',
      array('module' => 'store', 'controller' => 'index', 'action' => 'index', 'cid' => 0, 'sku' => 0, 'rev' => 0)
  );

It should pass default values if they are not provided.

cdburgess
Well that's aggravating.. I swear I already gave that a shot and it didn't work, but you prompted me to try again - sure enough that's how you assign default values. Sorry for not being clear on the question, I knew the missing variables were causing the exception to be thrown I just didn't know how to assign default values. Anyway, thanks. Also thanks for explaining that routes are matched in reverse order! Everything is suddenly clear...
Mahdi.Montgomery
No worries. Happy coding!
cdburgess