0

I need to catch and process error, when i try to remove entity from db.

[Error deleting record: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (zdf.cats, CONSTRAINT FK_cats_Categories FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE NO ACTION ON UPDATE NO ACTION)]

i try to remove entity by button click in with "deleteURL"

  $dbCategories = new Application_Model_DbTable_Categories();
    $source = new Bvb_Grid_Source_Zend_Select($dbCategories->getCategoriesByAppId(1, true));
        $columns = array('title', 'actions');
        $columnsPositions = array('title');
        $extraColumns = array(
            0 => $this->createExtraColumn(array(
                'name' => 'actions',
                'position' => 'right',
                'title' => 'Actions',
                'decorator' => '<a class="edit-button" href="{{editUrl}}">&nbsp;</a><a class="remove-button" href="{{deleteUrl}}">&nbsp;</a>'
            ))
    );

2 Answers 2

1

Since I couldn't find how to catch this error with ZF DataGrid without doing something in the component library, I've made delete by myself depending on URL params.

Basicly,

$deleteId =  $this->getRequest()->getParams('Delete');

then Try...Catch block with $model->delete($id);

and manually handle exception.

Sign up to request clarification or add additional context in comments.

Comments

0

How about using a Try/Catch block?

try {
    $dbCategories = new Application_Model_DbTable_Categories();
    $source = new Bvb_Grid_Source_Zend_Select($dbCategories->getCategoriesByAppId(1, true));
    $columns = array('title', 'actions');
    $columnsPositions = array('title');
    $extraColumns = array(
        0 => $this->createExtraColumn(array(
            'name' => 'actions',
            'position' => 'right',
            'title' => 'Actions',
            'decorator' => '<a class="edit-button" href="{{editUrl}}">&nbsp;</a><a class="remove-button" href="{{deleteUrl}}">&nbsp;</a>'
        ))
    );
} catch (Exception $e) {
    // handle exception here...
}

2 Comments

tried... doesn't catch it there...i understand that it should be like that, but can't figure out where should be this try catch block... this confuses me.
Interesting. Is it being thrown as a regular PHP error, not an exception? How about using set_error_handler() to catch all PHP errors and throw them as exceptions instead? I do this on all my projects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.