0

I want to make customer route for url which have parameters.

 <a href='javascript:void(0)' onclick="window.location='<?php echo 
 $this->url(array('module' => 'courses', 'controller' => 'course', 'action' => 'add', 
'std_id' => $entry['std_id']), 'coursesadd', TRUE); ?>'">add course</a>

and here what I make routing

$route = new Zend_Controller_Router_Route('courses/std_id/:std_id', 

array('module' => 'courses', 'controller' => 'course', 'action' => 'add'));

$routesArray = array('coursesadd' => $route );

$router->addRoutes($routesArray);

But It doesn't route correctly!

5
  • 1
    what is it doing wrong? When you navigate to /course/std_id/5 what happens? I will say that when using the url() helper you either have the module/controller/action as key pairs or you have a name for the route. so $this->url(array('std_id' => $entry['std_id']), 'courseadd') would be more correct. Commented Apr 1, 2012 at 10:19
  • This error occur Zend_Controller_Router_Exception: std_id is not specified Commented Apr 1, 2012 at 10:32
  • did that error occur using the url helper or by navigating to a url? Commented Apr 1, 2012 at 10:36
  • It occurs when I click on an anchor which have URL helper, but I have a navigation menu in my project, may it cause the problem?! Commented Apr 1, 2012 at 10:41
  • 1
    probably not, I just wanted to know the method of the test. Of course check and make sure $entry['std_id'] is being set correctly. you may need the TRUE switch in the Url helper. Url Helper may help explain. Commented Apr 1, 2012 at 10:48

1 Answer 1

1

Your code looks fine, except what RockyFord sad - You should only pass these parameters to url() helper which are required by designated route (when 'default' route is used indeed it requires module, controller, action, but Your 'coursesadd' route requires only std_id parameter). Moreover You should improve Your route a little bit to:

$route = new Zend_Controller_Router_Route('courses/:std_id', array(
   'module'     => 'main',
   'controller' => 'product',
   'action'     => 'add',
   'std_id'     => null //default value if param is not passed
));

The param_name/:param_value construction in Your route is redundant because You already named the parameter, so by using above route You'll get std_id param in controller using

$this->_getParam('std_id')

Default value in route definition would save from throwing Zend_Controller_Router_Exception: std_id is not specified but it looks like $entry['std_id'] is not set.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.