Zend: Problemas al configurar editAction (), por favor avise

I am experiencing some difficulty setting up the functionality for an admin to edit an items values. I have created the editAction() en función de la AdminItemController class. This is contained within a module called catalog. My routing is configured as the following:

resources.router.routes.admin-catalog-edit.route = "/admin/catalog/item/edit/:id"
resources.router.routes.admin-catalog-edit.defaults.module = "catalog"
resources.router.routes.admin-catalog-edit.defaults.controller = "admin.item"
resources.router.routes.admin-catalog-edit.defaults.action = "edit"

I have created a custom Zend_Form class and within this class I set the action and method for the form:

class My_Form_ItemAdd extends Zend_Form
    public function init()

Within my controller action I have instantiated the form and pass it to the view to be rendered. I also test if it's a POST (if so validate and save to database), otherwise, test for GET (if so, extract ID and populate()):

class Catalog_AdminItemController extends Zend_Controller_Action
    public function editAction()
        $form = new My_Form_ItemEdit();
        $this->view->form = $form;

The form loads just fine in the browser when I supply an ID at the end for GET request... however, when I submit the form an exception is thrown with the following request parameters:

array (
    'controller' => 'admin',
    'action' => 'catalog',
    'item' => 'edit',
    'module' => 'default',

I have no idea why the it would be doing this... is there something I'm not seeing??? Any advice would be much appreciated!

preguntado el 01 de febrero de 12 a las 14:02

1 Respuestas

The problem lies in your route. The default behavior for /admin/catalog/item/edit/:id is to process it like /controller/action/:param/:param/:param which puts both item y la edit as parameters instead of your intended purpose. Try adding something like this to your bootstrap:

protected function _initRoutes()
    // Get front controller
    $front = Zend_Controller_Front::getInstance();

    // Get router
    $router = $front->getRouter();

    // Add route
            new Zend_Controller_Router_Route('admin/catalog/item/edit/:id',
                                        array('controller' => 'item',
                                              'action' => 'edit'))


This allows you to define the specific controller and action from the route.

Respondido 01 Feb 12, 19:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.