hi there

im kinda new to cakephp, just 3 simple website i've done using it
but now im facing a problem, my web site has two language , english
and arabic, im loading a global array of language ($lang['var'] =
$word) from DB table called lang, i constructed the following

* 'Lang' Model
* 'LangController' Controller
no view

an example url : www.example.com/news/view/1    // this should
displayed in the default language which is arabic

another url: www.example.com/en/news/view/1  // obviously this is
should be in english

so i need to put a code to be run before any other controller, that
load the global lang array and remove '/en/' from url and dispatch the
new correct url internaly


my idea that i got for this (and i know it's so bad) :
in file /cake/app_controller.php

class StartupController extends Controller {

        var $definedLangs = array('ar', 'en');

        function __construct() {
                parent::__construct();
                $this->redirectToLang();
        }


        function redirectToLang()
        {
                //code to get controller name

                if($this->isLang($langcode))
                {
                        // dispatching new url

                }
                else
                {      // default
                        $this->loadLang('ar');
                }
        }

        // check if the missing controller is lang or not
        function isLang($name)
        {
                //code
        }

        function loadLang($langcode = 'ar')
        {
                loadModel('Lang');
                $lng = new Lang();
                $arr = $lng->findAll();

                global $lang;
                $lang = array();

                foreach($arr as $index)
                        $lang[$index['Lang']['var']] = 
$index['Lang'][$langcode];

                return $lang;
        }



}

class AppController extends StartupController {


}

im sure writing code in cake dir is extremely bad . so any ideas ?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to