PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, March 13, 2022

[FIXED] How to use custom exception from cakephp plugin?

 March 13, 2022     cakephp, php, plugins     No comments   

Issue

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...???


Solution

Lets say you want to put your exceptions in Custom plugin /app/Plugin/Custom/Lib folder:

// Location: /app/Plugin/Custom/Lib/CustomException.php
<?php
class CustomException extends CakeException {};

Now you need to load Custom plugin in /app/Config/bootstrap.php:

// Location: /app/Config/bootstrap.php
CakePlugin::load('Custom');

And wherever you want to use CustomException:

<?php
App::uses('CustomException', 'Custom.Lib');

class ApiController extends AppController {   

    public function demo() {
        throw new CustomException("Just testing");
    }

}


Answered By - Mindaugas Norvilas
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing