I have some custom exception for my application. I placed them to app where it is running well. Now I want to move them to one of my plugin and use exception from their.
I have implemented custom exception as mentioned here: http://book.cakephp.org/2.0/en/development/exceptions.html
But, I am looking for same solution if I use exception classes from cakephp plugin.
Any suggestion…???
Advertisement
Answer
Lets say you want to put your exceptions in Custom plugin /app/Plugin/Custom/Lib folder:
JavaScript
x
// Location: /app/Plugin/Custom/Lib/CustomException.php
<?php
class CustomException extends CakeException {};
Now you need to load Custom plugin in /app/Config/bootstrap.php:
JavaScript
// Location: /app/Config/bootstrap.php
CakePlugin::load('Custom');
And wherever you want to use CustomException
:
JavaScript
<?php
App::uses('CustomException', 'Custom.Lib');
class ApiController extends AppController {
public function demo() {
throw new CustomException("Just testing");
}
}