1

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)

tereško
  • 58,060
  • 25
  • 98
  • 150
Fabman22
  • 183
  • 12
  • See this answer on how to get post and other data in zend framework 2: http://stackoverflow.com/a/12077127/923847 – Matsemann Jan 02 '14 at 22:24

2 Answers2

1

I think you mean:

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

assuming you're trying to grab a POST variable.

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
  • Yeah thanks! But I have still a problem - I can´t get the value of the hidden field (see the phtml form code) - Is there something wrong with the form? btw - the http post includes no data in firebug.. – Fabman22 Jan 02 '14 at 20:36
1

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;?>">
Elie
  • 13,693
  • 23
  • 74
  • 128