Zend Framework 2 can´t receive HTTP Post - "get was unable to fetch or create an instance for fromPost"

785 views Asked by At

I´m new in ZF2 and I have a problem with reveiving the post/get Parameters in my Controller. Following Exception appears:

Zend\ServiceManager\Exception\ServiceNotFoundException

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

My 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>

...

And the Controller:

    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');
}

I think I have forgott something in the module.config, but I can´t find anything, how to declare the serviceManager right (module.config.php)

2

There are 2 answers

0
Elie On BEST ANSWER

Two changes are needed. First, as Tim wrote, it should be

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

Second, form items are passed to the controller by name, not id. So in addition to the id field on the element, you need a name field, as follows:

<input type="hidden" id="checklist" name="checklist" value="<?php echo $index;?>">
1
Tim Fountain On

I think you mean:

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

assuming you're trying to grab a POST variable.