Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 名称为“的路线”;博客;找不到_Php_Zend Framework2_Zend Form - Fatal编程技术网

Php 名称为“的路线”;博客;找不到

Php 名称为“的路线”;博客;找不到,php,zend-framework2,zend-form,Php,Zend Framework2,Zend Form,我跟在后面 我有以下代码: edit.phtml: <h2>EDIT FORM</h2> <?php $form = $this->form; $form->setAttribute('action', $this->url('post/edit', array('id' => $this->id), true)); $form->prepare(); $form->get('submit')->

我跟在后面

我有以下代码:

edit.phtml:

 <h2>EDIT FORM</h2>

 <?php

  $form = $this->form;
  $form->setAttribute('action', $this->url('post/edit', array('id' => $this->id), true));
  $form->prepare();
  $form->get('submit')->setValue('Update Post');

  echo $this->form()->openTag($form);

  echo $this->formCollection($form);

  echo $this->form()->closeTag();
module.config.php:(路由部分)

问题:

 <h2>EDIT FORM</h2>

 <?php

  $form = $this->form;
  $form->setAttribute('action', $this->url('post/edit', array('id' => $this->id), true));
  $form->prepare();
  $form->get('submit')->setValue('Update Post');

  echo $this->form()->openTag($form);

  echo $this->formCollection($form);

  echo $this->form()->closeTag();
当我试图通过like
http://www.myzend.com/blog/edit/2
我得到以下错误

找不到名为“blog”的路由

注意:当我在
edit.phtml
中只放入静态html时,静态内容的页面显示正确

我使用的是
Zend Framework 2.3.3


如果您需要更多详细信息,请告诉我。

尝试将“may_terminate”=>true`添加到您的子路由中(并检查类型os,以防万一:)。我在
编辑
路由下添加了“may_terminate”=>true`如果它与上面的代码示例中相同,则它位于错误的位置。它需要在
edit
键下的数组中——现在它在它之外。代码更新了,我怀疑它在
edit.phtml
中的配置是否正确,就像在$form->setAttribute('action',$this->url('blog/edit',array('id'=>$form->id),true)中一样;没错,我没有注意到这一点:你引用了
blog/edit
,你的路线是
post/edit
。在模板中尝试后一种方法。尝试将“may_terminate”=>true`添加到您的子路由(并检查类型os,以防万一:)。我在
edit
route下添加了“may_terminate”=>true`如果它与上面的代码示例中相同,则它位于错误的位置。它需要在
edit
键下的数组中——现在它在它之外。代码更新了,我怀疑它在
edit.phtml
中的配置是否正确,就像在$form->setAttribute('action',$this->url('blog/edit',array('id'=>$form->id),true)中一样;没错,我没有注意到这一点:你引用了
blog/edit
,你的路线是
post/edit
。在模板中尝试后一种方法。
'router'=>array(

    'routes'=>array(

        'post'=>array(

            'type'=>'literal',

            'options'=>array(

                'route'=>'/blog',
                'defaults'=>array(

                    'controller'=>'Blog\Controller\List',
                    'action'=>'index'


                )
            ),
            'may_terminate'=>true,
            'child_routes'=>array(

                'detail'=>array(
                    'type'=>'segment',
                    'options'=>array(
                        'route'=>'/:id',
                        'defaults'=>array(
                            'action'=>'detail'
                        ),
                        'constraints'=>array(
                            'id'=>'\d+'
                        )
                    )
                ),
                 'add'=>array(
                     'type'=>'literal',
                     'options'=>array(
                     'route'=>'/add',
                     'defaults'=>array(
                        'controller'=>'Blog\Controller\Write',
                        'action'=>'add'
                        )
                    )
                ),
               'edit' => array(
                     'may_terminate'=>true,
                     'type' => 'segment',
                     'options' => array(
                         'route'    => '/edit/:id',
                         'defaults' => array(
                             'controller' => 'Blog\Controller\Write',
                             'action'     => 'edit'
                         ),
                         'constraints' => array(
                             'id' => '\d+'
                         )
                     )
                 ),

             )
        ),


    )
),