Saturday, January 19, 2013

Re: Load different config file

On Sat, Jan 19, 2013 at 7:37 AM, MetZ <metz80@gmail.com> wrote:
> I did it like this:
>
> bootstrap.php
>
> if (isset($_SERVER['SERVER_NAME'])) {
> $tld = strrchr($_SERVER['SERVER_NAME'], ".");
> $tld = substr ($tld, 1);
> }
> if (!empty($tld)) {
> if ($tld == 'se') {
> Configure::load('config_se');
> }
> elseif ($tld == 'dk') {
> Configure::load('config_dk');
> } else {
> Configure::load('config_no');
> }
> } else {
> Configure::load('config_no');
> }
>
> Anyone have any suggestions on a better approach?
>

// put default locale first
$locales = array('no', 'se', 'dk');
$config_loaded = false;

// should not trust $_SERVER, btw
if (isset($_SERVER['SERVER_NAME'] && !empty($_SERVER['SERVER_NAME']))
{
$locale = substr($_SERVER['SERVER_NAME'], -2);
$config_loaded = Configure::load("config_${locale}");
}

if ($config_loaded === false)
{
Configure::load("config_${locales[0]}");
}

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate