ddattee
ddattee

Reputation: 25

Make Zend find my custom application exceptions

I have a question similar to this thread : [throwing-exceptions-from-model-view-controller-in-a-zend-framework-application][1]

I have a standard MVC structure like this:

/application
/myapp
    /controllers
    /forms
    /models
    /exceptions
        Default.php (class Myapp_Exception_Default extends Zend_Exception)

And no matter what when I try to do:

throw new Myapp_Exception_Default();

I get :

Fatal error: Class 'Myapp_Exception_Default' not found

My question is how to make Zend find my custom Exceptions ? I didn't find any configuration options to declare it.

Upvotes: 0

Views: 639

Answers (1)

max4ever
max4ever

Reputation: 12142

You should have something like this:

boostrap.php

With this content:

...

protected function _initAutoload()
{
    // Add autoloader empty namespace
    $autoLoader = Zend_Loader_Autoloader::getInstance();
    $autoLoader->suppressNotFoundWarnings(true);//http://zend-framework-community.634137.n4.nabble.com/Trouble-using-Gdata-Calendar-td675383.html
    $autoLoader->registerNamespace('Gestionale_');
    $resourceLoader = new Zend_Loader_Autoloader_Resource(
        array(
            'basePath' => APPLICATION_PATH,
            'namespace' => '',
            'resourceTypes' => array(
                'form' =>
                    array(
                        'path' => 'forms/',
                        'namespace' => 'Form_',
                    ),
                'model' =>
                    array(
                        'path' => 'models/',
                        'namespace' => 'Model_'
                    ),
            ),
    ));
    // Return it so that it can be stored by the bootstrap
    return $autoLoader;
}

...

\library\Gestionale\Exceptions\Exception.php

with this code

<?php
/**
 * Custom exception class that logs messages
 */
class Gestionale_Exceptions_Exception extends Exception
{
...
}

and then use

throw new Gestionale_Exceptions_Exception('Bla bla bla');

Upvotes: 1

Related Questions