Pergunta

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'
    )

),

);

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top