Hello i had the same problem , and i created an "Misc" namespace for my custom exceptions like so :
- add namespace to module.php
<?php
namespace Api;
use Phalcon\Loader,
Phalcon\Mvc\View,
Phalcon\Config\Adapter\Ini,
Phalcon\Mvc\ModuleDefinitionInterface,
Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
class Module
{
public function registerAutoloaders()
{
$loader = new Loader;
$loader->registerNamespaces([
'Api\Controllers' => __DIR__ . '/controllers/',
'Api\Models' => __DIR__ . '/models/',
'Api\Misc' => __DIR__ . '/misc/' // <<<<=== here
]);
$loader->register();
}
2 - create the folder "misc"
3 - in the folder create your class like so:
<?php
namespace Api\Misc; // <== namespace we just created
use \Phalcon\Exception;
class ApiExceptions extends \Phalcon\Exception // <= class name so we can access it later in our controllers
{
public static function InvalidCsrfToken()
{
throw new Exception("Invalid CSRF Token", 6);
}
4 - start using it !
use Api\Misc\ApiExceptions as ApiException; // <== class name that we created