Php 名称为“的路线”;博客;找不到
我跟在后面 我有以下代码: edit.phtml: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')->
<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();
当我试图通过likehttp://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+'
)
)
),
)
),
)
),