1

我是 ZF2 的新手,在我的控制器中接收 post/get 参数时遇到问题。出现以下异常:

Zend\ServiceManager\Exception\ServiceNotFoundException

Zend\Mvc\Controller\PluginManager::get was unable to fetch or create an instance for fromPost

我的 index.phtml

...

<form id="formActionCl" action="/public/checklistCore/delete" method="post">
    <input type="submit" id="butto_doAction<?php echo $index;?>" hidden="true" value="<?php echo $this->translate('button_confirm_action', 'checklist');?>"/>
    <input type="hidden" id="checklist" value="<?php echo $index;?>">
</form>

...

和控制器:

    use Zend\Mvc\Controller\Plugin\AbstractPluginManager,

...

public function deleteAction()
{
    $cl_id = $this->fromPost('checklist');
    echo $cl_id;
    //$cl_id = $_GET['checklist'];
    $checklist = $this->getEntityManager()->getRepository('ChecklistCore\Entity\Checklist')->find($cl_id);
    $checklist->status = 'inactiv';

    $this->getEntityManager()->persist($checklist);
    $this->getEntityManager()->flush();

    return $this->redirect()->toUrl('index');
}

我想我忘记了 module.config 中的某些内容,但我找不到任何东西,如何声明 serviceManager 正确(module.config.php

4

2 回答 2

1

我想你的意思是:

$cl_id = $this->params()->fromPost('checklist');

假设您正在尝试获取 POST 变量。

于 2014-01-02T19:57:26.050 回答
1

需要进行两项更改。首先,正如蒂姆所写,它应该是

$cl_id = $this->params()->fromPost('checklist');

其次,表单项通过名称而不是 id 传递给控制器​​。所以除了元素上的id字段外,还需要一个name字段,如下:

<input type="hidden" id="checklist" name="checklist" value="<?php echo $index;?>">
于 2014-01-02T20:43:38.557 回答