9
votes

I've been reading CakePHP's 2.0 migration guide where it's stated that cakeError() has been removed because it was used for exceptions. It's a really weird change IMHO because I used it to block access to unauthorized users or to trigger an error when the paginated items exceeded the total, and things like that.

And now what? Should I just throw a die() or a redirect? I really want to let know the users that something was not found and Cake used to provie a stright way to do so... now it doesn't.

Any thoughts/hacks/workarounds about it? Thanks, happy holidays!

2

2 Answers

13
votes

You have to throw the corresponding exception, in your case the NotFoundException:

throw new NotFoundException();

See also the chapter about exceptions in the cook book.

0
votes

try this

if ($this->Session->read('Auth.User.role') == 'P' || $this->Session->read('Auth.User.role') == 'U') {
            //die('you are not allowed to access this page');
            //throw new ForbiddenException;
            throw new NotFoundException('404 Error - Page not found');
        }