简体   繁体   English

Zend框架编辑记录

[英]Zend framework edit a record

I am trying to create edit records functionality in my listing page. 我正在尝试在列表页面中创建编辑记录功能。 But i am getting following error when clicking on edit link against record. 但是我点击针对记录的编辑链接时遇到以下错误。

A 404 error occurred Page not found. 发生404错误找不到页面。

The requested URL could not be matched by routing. 路由无法匹配请求的URL。 No Exception available 没有例外

My module.config.php file code for edit view is : 我用于编辑视图的module.config.php文件代码是:

'edit' => array(
            'type' => 'literal',
            'options' => array(
                'route'    => '/album[/][:action][/:id]',
                     'constraints' => array(
                         'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                         'id'     => '[0-9]+',
                ),
                         'defaults' => array(
                         'controller' => 'Application\Controller\Album',
                         'action'     => 'edit',
                     ),
            ),
        ),

And my Album listing page code for calling edit controller and passing id to is : 我的相册列表页面代码(用于调用编辑控制器并将ID传递给)是:

<a href="<?php echo $this->url('edit',
             array('action'=>'edit', 'id' => $album->id));?>">Edit</a>

and editAction code is : 和editAction代码是:

$id = (int) $this->params()->fromRoute('id', 0);

Please let me know what im missing. 请让我知道我错过了什么。 I am new to zend framework. 我是zend框架的新手。

i think you have to use 'type' => 'segment' have a look on the documentation 我认为您必须使用'type' => 'segment'来查看文档

<?php
'edit' => array(
    'type'    => 'segment', /* <--- use segment*/
    'options' => array(
        'route'       => '/album[/][:action][/:id]',
        'constraints' => array(
            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
            'id'     => '[0-9]+',
        ),
        'defaults'    => array(
            'controller' => 'Application\Controller\Album',
            'action'     => 'edit',
        ),
    ),
),

Advise regarding the type option is correct, however you will also need the may_terminate option to ensure that the router knows that this route can be matched . 关于type选项的建议是正确的,但是您还需要may_terminate选项,以确保路由器知道此路由可以匹配

 'edit' => array(
        'type' => 'segment',
        'options' => array(
            'route'    => '/album[/][:action][/:id]',
                 'constraints' => array(
                     'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                     'id'     => '[0-9]+',
            ),
            'defaults' => array(
                 'controller' => 'Application\Controller\Album',
                 'action'     => 'edit',
            ),
        ),
        'may_terminate' => true, // Add this line
    ),

See now my route script in module.config.php is this. 现在看到我在module.config.php中的路由脚本是这个。

'album' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/album/',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Album',
                    'action'        => 'album',
                ),
            ),
            'may_terminate' => true,
                'child_routes' => array(
                 'add' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/album/[:add]',
                'constraints' => array(
                                'add' => '[a-zA-Z0-9_-]+'
                            ),
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Album',
                    'action'        => 'add',
                ),
            ),
        ),
        'edit' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/album/[:edit][/:id]',
                'constraints' => array(
                                'edit' => '[a-zA-Z0-9_-]+'
                            ),
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Album',
                    'action'        => 'edit',
                ),
            ),
        ),
),
    ),

in this case if i am clicking on any link only the album page displaying not other which i am hitting. 在这种情况下,如果我单击任何链接,则仅相册页面不显示我所点击的其他页面。

Finally i got solution and now my application is working perfectly.... I just replace above code with : 终于我有了解决方案,现在我的应用程序运行正常。

'album' => array(
                 'type'    => 'segment',
                 'options' => array(
                     'route'    => '/album[/][:action][/:id]',
                     'constraints' => array(
                         'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                         'id'     => '[0-9]+',
                     ),
                     'defaults' => array(
                         'controller' => 'Application\Controller\Album',
                         'action'     => 'album',
                     ),
                 ),
             ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM