3

I see lots of examples of people doing marvellous things starting with:

$locale = $this->getResource('locale');

in their bootstrap. But though I have

resources.locale.default = "nl_NL"
resources.locale.force = true

in my application.ini and

protected function _initLocale()
{
    $locale = $this->getResource('locale');
    // more code
}

var_dump($locale) still returns NULL and the locale applied elsewhere in my application is the zend default of "en(_US)".

What should I do to access (or initialise) the application wide locale set in my application.ini?

Siguza
  • 21,155
  • 6
  • 52
  • 89
tihe
  • 2,452
  • 3
  • 25
  • 27

1 Answers1

4

The problem here is that your Bootstrap method overrides the built-in application resource because it has the same name (the part after _init).

Try this instead

protected function _initLocaleMods()
{
    // always bootstrap required resources
    $this->bootstrap('locale');

    $locale = $this->getResource('locale');

    // more code
}
Phil
  • 157,677
  • 23
  • 242
  • 245
  • Thx Phil, this works! Though the bootstrap('locale') is indeed necessary here: why should I always bootstrap resources? I do not do this for view, db, mail etc and my application.ini settings still are getting picked up elsewhere. – tihe Nov 02 '11 at 12:14
  • @zensys The order of app resource and bootstrap method is not guaranteed so you should always ensure resources that your code depends on are ready for use. You would only bootstrap view, db, etc if your method or custom resource plugin depended on them. Read [Dependency Tracking](http://framework.zend.com/manual/en/zend.application.theory-of-operation.html#zend.application.theory-of-operation.bootstrap.dependency-tracking) – Phil Nov 02 '11 at 12:16