0

I have the following function in my app_controller:

function beforeFilter() {
    $this->set('lastThreePosts', $this->Blog->find_latest_posts());
}

I then use the variable 'lastThreePosts' that I have set in my layout. This works fine apart from on my 404 page where I get the following error:

Notice (8): Undefined index: lastThreePosts [APP\views\layouts\default.ctp, line 29]

I have made my own 404 page by created the file error404.ctp in my /views/errors/ directory.

So it seems when theres a 404 error the code in the controller doesn't get executed. Does anyone know how I can make it work?

Thanks

1
  • Why are you doing that in the beforeFilter? While it isn't necessarily wrong, it isn't necessarily right either as you will be performing that query before every method called on that controller. Commented Dec 24, 2010 at 23:25

1 Answer 1

2

Phew! I found the answer here:

http://www.bradezone.com/2009/05/21/cakephp-beforefilter-and-the-error-error/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.