1

私は ZF2 を初めて使用し、コントローラでポスト/取得パラメータを取得する際に問題があります。次の例外が表示されます。

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

2 つの変更が必要です。まず、ティムが書いたように、

$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 に答える
1

私はあなたが意味すると思います:

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

POST 変数を取得しようとしていると仮定します。

于 2014-01-02T19:57:26.050 に答える