Andrew Myers
Andrew Myers

Reputation: 461

In CakePHP, how do I make data from a table available to all controllers

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.

Upvotes: 0

Views: 89

Answers (2)

evotopid
evotopid

Reputation: 5429

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.

Upvotes: 0

user1548335
user1548335

Reputation:

In your AppController put:

public $uses = array('Country'); //list of models
public $countries = $this->Country->find('all');

Upvotes: 1

Related Questions