接收:“未找到名称为“ imageAdd”的路由”

时间:2019-04-27 14:57:09

标签: php zend-framework routing

我在Zend3中收到有关在定义我的路由的module.config.php文件中定义的路由的错误。

这是导致错误的我的视图文件上的链接:

    <p>
        <a href="<?= $this->url('property/imageAdd', ['p_id' => $property->p_id]) ?>">Add Image</a>
    </p>

这是我的路由器设置:

    'router' => [
        'routes' => [
            'property' => [
                'type' => Segment::class,
                'options' => [
                    'route'     => '/property',
                    'defaults' => [
                        'controller'    => Controller\ListController::class,
                        'action'        => 'forsale',
                    ],
                    'constraints' => [
                        'action'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                    ],
                ],
                'may_terminate' => true,
                'child_routes'  => [

                    'detail' => [
                        'type' => Segment::class,
                        'options' => [
                            'route'     => '/detail[/:p_id]',
                            'defaults'  => [
                                'action' => 'detail',
                            ],
                            'constraints' => [
                                'p_id'      => '[1-9]\d*',
                            ],
                        ],
                    ],

                    'add' => [
                        'type' => Literal::class,
                        'options' => [
                            'route'     => '/add',
                            'defaults'  => [
                                'controller'    => Controller\WriteController::class,
                                'action'        => 'add',
                            ],
                        ],
                    ],

                    'imageAdd' => [
                        'type' => Segment::class,
                        'options' => [
                            'route'     => '/imageAdd[/:p_id]',
                            'defaults'  => [
                                'controller'    => Controller\WriteController::class,
                                'action'        => 'imageAdd',
                            ],
                            'constraints' => [
                                'p_id'      => '[1-9]\d*',
                            ],
                        ],
                    ],             
                ],
            ],
        ],
    ],

我们将非常感谢您能提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

您应该仅将父级“属性”路由定义为文字类型,而不是细分类型。这样就足以启用对子路由的访问。