0

I've recive an error when run I run "localhost/products/edit" what's wrong I have done ? Ofcourse I have function edit in Product controller classand edit.html in view.

 'products' => array( 'type' => 'Literal', 'options' => array( 'route' => '/products', 'defaults' => array( '__NAMESPACE__' => 'Application\Controller', 'controller' => 'Products', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( 'default' => array( 'type' => 'Segment', 'options' => array( 'route' => '/products[/:action]', 'constraints' => array( 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ), 'defaults' => array( ), ), ), ), ), ), ), 'controllers' => array( 'invokables' => array( 'Application\Controller\Index' => 'Application\Controller\IndexController', 'Application\Controller\Products' => 'Application\Controller\ProductsController' ) ), 

);

2
  • What is the error message? And probably worth posting a striped down controller if you can. Commented May 7, 2014 at 11:32
  • "A 404 error occurred Page not found. The requested URL could not be matched by routing. No Exception available" Commented May 7, 2014 at 11:34

1 Answer 1

1

Try this as your child roots array:

'child_routes' => array( 'view' => array( 'type' => 'segment', 'options' => array( 'route' => '/:id', 'constraints' => array( 'id' => '[0-9]+', ), 'defaults' => array( 'action' => 'view', ), ), 'may_terminate' => true, 'child_routes' => array( 'actions' => array( 'type' => 'segment', 'options' => array( 'route' => '/:action', 'constraints' => array( 'id' => '[0-9]+', ), 'defaults' => array( 'controller' => 'Application\Controller\ProductsController, 'action' => 'view', ), ), ), ), ), ), 

Also it needs to be localhost/products/[:id]/edit like localhost/products/1/edit not localhost/products/edit I would imagine anyway but I don't know what your doing to be fair. Just remove the id parameter and constraint and it should work

Notice child root actions do not have the route repeated as it is inherited... your route would create something like /products/products/edit

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

7 Comments

ok now I have in child route => /:action , works fine :) bu in view file using echo $this->url('products', array('action'=>'edit')); return only /products/ :(
$this->url('products/actions', array('action'=>'edit'));
But you need to update default to actions as in my example or it will be $this->url('products/default', array('action'=>'edit')); maybe
Compare line under child_routes in your code and my example code and you should see what I mean
unfortunately ... I got an error: Route with name "actions" not found
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.