Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger a 404 error with CakePHP 2.0?

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!

like image 391
metrobalderas Avatar asked Dec 20 '11 04:12

metrobalderas


1 Answers

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.

like image 113
dhofstet Avatar answered Oct 06 '22 20:10

dhofstet