Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:33:10+00:00 2026-05-28T16:33:10+00:00

I’ve worked with CakePHP 1.3, but this is my first foray into CakePHP 2.0

  • 0

I’ve worked with CakePHP 1.3, but this is my first foray into CakePHP 2.0 and PHP exceptions, so bear with me if my question seems wordy.

In my AppController‘s beforeFilter() I set a couple of variables via $this->set() for use in my view template.

In my UsersController I have code that looks roughly like this:

public function beforeFilter() {
  parent::beforeFilter();
  if (userDeniedAccess()) {
    throw new ForbiddenException();
  }
}

where the hypothetical function userDeniedAccess() encapsulates my authorization checks.

This all works fine, and I get the 403 error when I expect it. However, when the exception is thrown, the view variables that were set in AppController::beforeFilter() are no longer set, resulting in errors from my view template. When the exception is not thrown, the variables are set correctly.

I can code around the missing variables if I must, but I’d really like to know what causes this behavior. Both my UsersController and the CakeErrorController extend AppController. Naturally, I expect that when the exception is thrown and the CakeErrorController is instantiated, it would generate the same view variables for me.

However, it seems that the Controller::startupProcess() method (which includes the call to beforeFilter()) never gets called on CakeErrorController. As I understand it, this is done by the dispatcher for regular requests, but the life-cycle of the error controller is different.

I’ve seen descriptions (like this one) of similar behavior in CakePHP 1.3, but of course CakePHP’s error handling code has been completely overhauled in 2.0.

So either:

  1. This is a bug in CakePHP’s default exception handling,
  2. The behavior is as intended and I just don’t understand it, or
  3. I’m going nuts.

I know you can’t help with case 3, but if either of the first two apply, I’d appreciate input from someone who knows more than I do.

Thanks!

EDIT: Setting the view variables in beforeRender() does solve my problem. However, I still wonder whether it is intentional that beforeFilter() never gets called on CakeErrorController.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:33:11+00:00Added an answer on May 28, 2026 at 4:33 pm

    Put the calls to $this->set() in the beforeRender() callback. That way, they’ll always be set even when you throw an exception.

    I had the same problem myself with some custom layout variables, as with DebugKit my page would be filled with undeclared variable warnings whenever there was any sort of error. Using beforeRender() instead fixed it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.