1

I've created an Adminhtml extension with a form and in the controller I have the saveAction(). I need to debug it and I need to see the values of $data, but var_dump($data); doesn't work, it just returns the success or error message.

This is the code that I have in my saveAction within the controller:

public function saveAction() {
        if ( $data = $this->getRequest()->getPost() ) {
            $this->_getSession()->setFormData( $data );
            $model = Mage::getModel( 'namespace_module/table' );
            $id    = $this->getRequest()->getParam( 'entity_id' );

            try {
                if ( $id ) {
                    $model->load( $id );
                }
                // TODO: filter out attributes we don't want to allow changes to
                $model->addData( $data )->save();

                $this->_getSession()
                     ->addSuccess( $this->__( 'Result was successfully saved' ) );
                $this->_getSession()->unsFormData();

                if ( $this->getRequest()->getParam( 'back' ) ) {
                    $params = array( 'id' => $model->getId() );
                    $this->_redirect( '*/*/edit', $params );
                } else {
                    $this->_redirect( '*/*/list' );
                }
            } catch ( Exception $e ) {
                $this->_getSession()->addError( $e->getMessage() );
                if ( $model->getId() ) {
                    $this->_redirect( '*/*/edit', array( 'id' => $model->getId() ) );
                } else {
                    $this->_redirect( '*/*/new' );
                }
            }

            return;
        }

        $this->_getSession()->addError( $this->__( 'No data found to save' ) );
        $this->_redirect( '*/*' );
    }

Could you guys help me with this?

Thanks.

2
3

You can add this line after if ( $data = $this->getRequest()->getPost() ) {

Mage::log($data, null, 'debug.log', true);

and the array will be logged in var/log/debug.log.
You are seeing the success message because the saveAction does not have an output. It just does a redirect to the edit page.

If you want you can use var_dump($data) but you need to stop the execution. add an exit after the var_dump statement.

1
  • how can I save data directly to the grid if am not getting that from API, Mar 3 '17 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.