Take the 2-minute tour ×

I have a list of countries and ccodes in a database. I would like to be able to put that data in to an array in the AppController so I can use it via $this->countries in my other controllers. A kind of $this->App->query() if you like. How can I do this please :) Thank you in advance.

share|improve this question
You answered your own question... Put it as a variable on the AppController and it will be available to all controllers that extend it. –  jeremyharris Jul 25 '12 at 14:23
add comment

2 Answers

up vote 1 down vote accepted

In your AppController put:

public $uses = array('Country'); //list of models
public $countries = $this->Country->find('all');
share|improve this answer
Green tick when it lets me. Thanks for that, had a brain crash but even though cakephp is new to me I'm really liking it. –  Andrew Myers Jul 25 '12 at 14:24
CakePHP is great. Once you learn it, you will have a great time coding your web applications. :) –  user1548335 Jul 25 '12 at 14:27
add comment

Why don't you just load the countries with a model?

You could use the model in every controller (at least I think).
This should work then: $this->Country->find('all')

If you don't want to write this every time you could also move it into a helper.

share|improve this answer
add comment

Your Answer


