Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon Transaction Manager getting 500 server error when rollback is triggered

Phalcom Transaction Manager getting 500 server error when rollback is triggered

https://drive.google.com/file/d/0B7AtJVATjxPFTDktdFFuRXlFM3c/view?usp=sharing

    $request = new Request();
    $guid = new Guid();
    $transactionManager = new TransactionManager();
    $transaction = $transactionManager->get();

    if($request->isPost()){

        $directoryid    = $guid->GUID();
        $memberid       = $request->getPost('memberid');
        $directorytitle = $request->getPost('directorytitle');
        $path           = $request->getPost('path');

        $findfolder = Membersdirectory::findFirst("directorytitle = '".$directorytitle."' AND path = '". $path ."'");
        if($findfolder){
            $data = array('error' => 'Folder is already exist!', 'statuscode' => 400 );
        }
        else{
            try {
                    $savefolder = new Membersdirectory();
                    $savefolder->setTransaction($transaction);

                    $savefolder->directoryid    = $directoryid;
                    $savefolder->memberid       = $memberid;
                    // $savefolder->directorytitle = $directorytitle;
                    $savefolder->path           = $path;
                    $savefolder->datecreated    = date('Y-m-d H:i:s');

                    if($savefolder->save()){
                        $data = array('success' => 'New folder successfully created!', 'statuscode' => 200 );
                        // $transaction->rollback();
                    }
                    else{
                        $data = array('error' => 'Something went wrong!', 'statuscode' => 400 );
                        $transaction->rollback();
                    }

                     $transaction->commit();

                } 

                catch (Phalcon\Mvc\Model\Transaction\Failed $e) {
                    echo "Failed, reason: ", $e->getMessage();
                }

        }

        echo json_encode($data);

    }


8.2k
Accepted
answer

Put a \ in front of the FQN so your catch block is:

catch (\Phalcon\Mvc\Model\Transaction\Failed $e) {...}

Also, your catch block should come directly after the closing bracket from the try block.

try {

} catch ($e) {

}
edited Mar '16

Put a \ in front of the FQN so your catch block is:

```php catch (\Phalcon\Mvc\Model\Transaction\Failed $e) {...} ```

Also, your catch block should come directly after the closing bracket from the try block.

```php try {

} catch ($e) {

} ```

thank you so much i fixed the problem thank you sir :) and one more question not related but how did you make your code dark background my code in description section is white but your code is dark how is that?

You can use code blocks, read about it in the markdown help page