Re: Call static function in bootstrap.php

2009-01-06 Thread gearvOsh

It will work fine in your AppController beforeFilter().
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Call static function in bootstrap.php

2009-01-05 Thread Daniel Hofstetter

Hi,

 I'm using a language controller to manage languages (activating and
 set to default functions etc...)
 How can i call a static function in bootstrap to load activated
 languages?

 ex:

 // get activated languages
 $languages = LanguagesController::getActivatedLanguages();

App::import() should do the trick.

Hope that helps!

--
Daniel Hofstetter
http://cakebaker.42dh.com
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Call static function in bootstrap.php

2009-01-05 Thread cyberscorp

Sorry, it doesn't work.

Any idea ? Thank you and sorry to bother you

***  bootstrap.php

// Encodage
// 
Configure::write('App.encoding', 'utf-8');


// Langues
// ---

// get actiavted languages
$languages = LanguagesController::getActivatedLanguages();

// get default langugage
$langdefault = LanguagesController::getDefaultLanguage();


// Default Langue
$langCode = $langdefault[0];
$language = $langdefault[1];

// Analyse de l'URL
if(!empty($_GET['url']))
{
if(strpos($_GET['url'], '/') !== false)
{
$langFromUrl = substr($_GET['url'], 0, strpos($_GET['url'], 
'/'));
}
else
{
$langFromUrl = $_GET['url'];
}

// Code langue accepté ?
if(isset($languages[$langFromUrl]))
{
$langCode = $langFromUrl;
$language = $languages[$langCode];

// On enlève le code langue et le slash au début de l'URL
// avant qu'elle ne soit transmise au Router
if(strlen($_GET['url'])  strlen($langFromUrl))
{
$_GET['url'] = substr($_GET['url'], 
strlen($langFromUrl));
}
else
{
$_GET['url'] = '/';
}
}
}

Configure::write('Config.languages', $languages);
Configure::write('Config.language',  $language);
Configure::write('Config.langCode',  $langCode);


*
languages_controllers.php

// returns activated languages
// return : array('code2letters' = 'code3letters', ...)
function getActivatedLanguages() {

$dbActivate = $this-Language-find('all',array('conditions'=
array('Language.active'=1)));

$lang = array();

if (!empty($dbActivate)) {
foreach ($dbActivate[Language] as $key=$value) {
$lang[$key] = $value;
}
}

// return activated languages else default array
if ( count($lang) )
 return $lang;
else
 return array('en' = 'eng');

}

// return default langugage
// return ; array('code2letters', 'code3letters')
function getDefaultLanguage() {
$dbDefault = $this-Language-findByDefault(1);
if (!empty($dbDefault))
 return array($dbDefault[Language][code2] , $dbDefault
[Language][code3]);
else
 return array('en' , 'eng');
}


On 5 jan, 13:52, Daniel Hofstetter dhofs...@gmail.com wrote:
 Hi,

  if i use :

  App::import('Controller', 'Languages');

  i got the following error:

  Fatal error: Class 'Controller' not found in /var/www/project/app/
  app_controller.php on line 2

 It seems like you also have to import the Controller class with
 App::import('Core', 'Controller');

 --
 Daniel Hofstetterhttp://cakebaker.42dh.com
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Call static function in bootstrap.php

2009-01-05 Thread cyberscorp

if i use :

App::import('Controller', 'Languages');

i got the following error:

Fatal error: Class 'Controller' not found in /var/www/project/app/
app_controller.php on line 2

Thanks

Daniel Hofstetter a écrit :
 Hi,

  I'm using a language controller to manage languages (activating and
  set to default functions etc...)
  How can i call a static function in bootstrap to load activated
  languages?
 
  ex:
 
  // get activated languages
  $languages = LanguagesController::getActivatedLanguages();

 App::import() should do the trick.

 Hope that helps!

 --
 Daniel Hofstetter
 http://cakebaker.42dh.com
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Call static function in bootstrap.php

2009-01-05 Thread Daniel Hofstetter

Hi,

 if i use :

 App::import('Controller', 'Languages');

 i got the following error:

 Fatal error: Class 'Controller' not found in /var/www/project/app/
 app_controller.php on line 2

It seems like you also have to import the Controller class with
App::import('Core', 'Controller');

--
Daniel Hofstetter
http://cakebaker.42dh.com
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Call static function in bootstrap.php

2009-01-05 Thread Daniel Hofstetter

Hi,

 Sorry, it doesn't work.

 Any idea ? Thank you and sorry to bother you

[code snipped]

Well, you cannot call a non-static method in a static way.

--
Daniel Hofstetter
http://cakebaker.42dh.com
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Call static function in bootstrap.php

2009-01-05 Thread Jon Bennett

Hi cyberscorp,

  Well, you cannot call a non-static method in a static way.

I think this should probably be handled by your app_controller rather
than in bootstrap, in beforeFilter at a guess. You then need to make
your 2 methods model methods not controller methods, and call them
like so:

// get actiavted languages
$languages = ClassRegistry::init('Language')-getActivatedLanguages();

// get default langugage
$langdefault = ClassRegistry::init('Language')-getDefaultLanguage();

ClassRegistry::init('Language')-getActivatedLanguages();

This might also work from bootstrap, it might not - worth a shot eh!

hth

Jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---