Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Director:addRules generates a Class not found error - Silverstripe 2.3 rc3


Reply


2109 Views

Avatar
danbalbo

Community Member, 6 Posts

17 February 2009 at 4:41am

Hello to everyone,
i am building a web multi language website on Silverstripe 2.3 release candidate 3 and i am getting this error:

Fatal error: Class 'MultiLanguage' not found in /var/www/northstargroup/sapphire/core/control/Director.php on line 259

I am following this how to avaibile on silverstripe help http://doc.silverstripe.org/doku.php?id=recipes:multilingual_content&s=multilingual

MultiLanguage Class is under mysite directory and here is the code:

class MultiLanguage extends ModelAsController {   
   static $lang;   
   
   function init() {
      $baseUrl = Director::baseUrl();
      $requestUri = $_SERVER['REQUEST_URI'];
      $lang = substr($requestUri, strlen($baseUrl), 2);      
      self::$lang = $lang;
      //prevents default behaviour of redirecting to '/' for '/en/'
      if($this->URLParams['URLSegment'] == "" || $this->URLParams['URLSegment'] == 'home') {
         $urlparams = array('URLSegment' => 'home', 'Action' => ' ');
         $this->setURLParams($urlparams);
      }      
      parent::init();
   }
   
   static function currentLang() {
      return self::$lang;
   }
   
   protected function getField($field) {      
      //$lang = $this::currentLang();
      $lang = "en";
      $langField = $field.'_'.$lang;
      if(isset($this->record[$langField])) {
         return $this->record[$langField];
      } else {
         return isset($this->record[$field]) ? $this->record[$field] : null;
      }
   }   
}

In my _config file i have added this:

//
Director::addRules(100, array(
   'en/$URLSegment/$Action/$ID/$OtherID' => 'MultiLanguage'
));

but i am getting a Fatal error when i try to access pages like "domain.com/en/page-name" ( no problems with "domain.com/page-name" )

Any idea about it?