1
votes

I have a CakePHP model that uses the TranslateBehavior for i18n. In most contexts it works fine, however when I try to retrieve data from it in a CakePHP shell the result is always an empty array. So this:

$this->MyModel->find('all')

returns lots of records in a controller, but nothing in a shell. I have tried both adding the model to the shell's $uses array, and also by doing $this->MyModel = ClassaRegistry::init('MyModel'). I haven't found anything in the docs that suggests this shouldn't work, and Googling has not revealed anyone else with this problem (I also asked in the CakePHP IRC), but I'm not sure how to debug.

1

1 Answers

3
votes

When beeing accessed from a controller, the I18n classes have been setup already and the behavior knows which language to choose. From a shell no session and/or browser identification is known, so there will be no language selected.

You can overcome this by putting

Configure::write('Config.language', 'en');

or add

$this->MyModel->locale = 'en';

to your shell before using the model in question.