Welcome Guest, Not a member yet? Register   Sign In
Update
#1

[eluser]Unknown[/eluser]
When i try to update i get this : Fatal error: Cannot redeclare class Locale in /home/tenrouis/public_html/admin/application/libraries/Locale.php on line 12
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* @version $Id$
* @package solaitra
* @copyright Copyright (C) 2005 - 2008 Tsiky dia Ampy. All rights reserved.
* @license GNU/GPL, see LICENSE.php
*/



class Locale {
//initializing
var $_data;
var $locale;
var $_l10n;
var $table;
var $codes;
var $default;

function Locale() {
  $this->table = ('languages');
  $this->obj =& get_instance();
  $this->codes = $this->get_codes();
  $this->default = $this->get_default();
  
  if (!$this->obj->session->userdata('lang')) {
   $this->obj->session->set_userdata('lang', $this->default);
  }

  log_message('debug', 'Locale Class Initialized');

}
/*
function load_messages()
{
  $handle = opendir(APPPATH.'modules');

  if ($handle)
  {
   while ( false !== ($module = readdir($handle)) )
   {
    
    // make sure we don't map silly dirs like .svn, or . or ..

    if (substr($module, 0, 1) != ".")
    {
     if ( file_exists(APPPATH . 'modules/'.$module.'/locale/' . $this->obj->session->userdata('lang') . '.mo' )) {
      //echo APPPATH . 'modules/'.$module.'/locale/' . $this->obj->session->userdata('lang') . '.mo' ;
      $this->load_textdomain(APPPATH . 'modules/'.$module.'/locale/' . $this->obj->session->userdata('lang') . '.mo', $module );
     }
    }
   }
  }
}
*/

function get_active()
{
  $this->obj->db->where('active', 1);
  $query = $this->obj->db->get($this->table);
  
  $languages = array();
  
  if ( $query->num_rows() > 0 )
  {
   $languages = $query->result_array();
  }
  
  return $languages;
}

function get_list()
{
  $query = $this->obj->db->get($this->table);
  
  $languages = array();
  
  if ( $query->num_rows() > 0 )
  {
   $languages = $query->result_array();
  }
  
  return $languages;
}

function get_default()
{
  $this->obj->db->select('code');
  $this->obj->db->where('default', 1);
  $this->obj->db->limit(1);
  $query = $this->obj->db->get($this->table);
  if ($query->num_rows() == 1)
  {
   $row = $query->row();
   return $row->code ;
  }
  elseif (strlen( $this->obj->config->item('language') ) == 2 )
  {
   return $this->obj->config->item('language');
  }
  else
  {
   return 'en';
  }
  
}
function get_codes()
{
  $this->obj->db->select('code');
  $this->obj->db->where('active', 1);
  $this->obj->db->order_by('ordering');
  $query = $this->obj->db->get($this->table);
  $codes = array();
  
  if ( $query->num_rows() > 0 )
  {
   foreach ( $query->result() as $row )
   {
    $codes[] = $row->code;
   }
  }
  return $codes;
}


function __($text, $domain = 'default') {

  if (isset($this->_l10n[$domain]))
   return $this->_l10n[$domain]->translate($text);
  else
   return $text;
}

function tr($text, $domain = 'default') {
  
  return $this->__($text, $domain);
}
function _e($text, $domain = 'default') {
  
  echo $this->__($text, $domain);
}

function __ngettext($single, $plural, $number, $domain = 'default') {

  if (isset($this->_l10n[$domain])) {
   return $this->_l10n[$domain]->ngettext($single, $plural, $number);
  } else {
   if ($number != 1)
    return $plural;
   else
    return $single;
  }
}
function load_textdomain($mofile, $domain = 'default') {
  
  
  include_once(APPPATH . 'libraries/gettext' . EXT);
  include_once(APPPATH . 'libraries/streams' . EXT);
  
  if (isset($this->_l10n[$domain]))
  
   return;

  if ( is_readable($mofile)) {
  
   $input = new CachedFileReader($mofile);
  
  }
  else
  {
   return;
  }
  //echo $domain;
  $this->_l10n[$domain] = new gettext_reader($input);
}
}

?>

When I take it out, I get this : Fatal error: Cannot redeclare __() (previously declared in /home/tenrouis/public_html/admin/application/helpers/locale_helper.php:10) in /home/tenrouis/public_html/admin/application/libraries/Locale.php on line 126
#2

[eluser]InsiteFX[/eluser]
Code:
function Locale() {

// should be
function __construct() {
#3

[eluser]goFrendiAsgard[/eluser]
@laxus: I think you have function __ in both, local_helper.php and Locale.php, try to rename the function name
@InsiteFX: I think your suggestion is a "best-practice", but what @laxus write is not wrong.
#4

[eluser]Unknown[/eluser]
I still get the same error.
#5

[eluser]PhilTem[/eluser]
[quote author="goFrendiAsgard" date="1343027015"]@InsiteFX: I think your suggestion is a "best-practice", but what @laxus write is not wrong.[/quote]

@goFrendiAsgard: If you refer to the __construct() rename, he's not referring to best-practice but more to PHP 5 conformity since __construct() is used as constructor and a function named the same as your class can either be the constructor (for PHP < 5.3.3) or a function that impractically was named the same as your class (for PHP >= 5.3.3)
#6

[eluser]TWP Marketing[/eluser]
Isn't this error caused by the same class name in application/libraries and in application/helpers?

When you remove the library file 'Locale.php', it may need a cache flush.
#7

[eluser]PhilTem[/eluser]
[quote author="TWP Marketing" date="1343071149"]Isn't this error caused by the same class name in application/libraries and in application/helpers?

When you remove the library file 'Locale.php', it may need a cache flush.[/quote]

You have classes in your application/helpers? You shouldn't have. The helpers are supposed to be functions that can be called and not methods of classes.
Or I got your point wrong Wink
#8

[eluser]TWP Marketing[/eluser]
No, you're correct. The helpers don't have a class name, not being a library.
I'm looking for what could generate the error message of the OP.
#9

[eluser]PhilTem[/eluser]
I don't have a clue yet about what is causing the error. However, I was just stumbling over this line when reading through the OP's code

Code:
$this->table = ('languages');

Maybe my PHP knowledge is too limited (even after almost 10 years of working with PHP), but what do the brackets do?

And furthermore: Could the OP please post the 'locale_helper.php' source code? Maybe the error is in there Wink
#10

[eluser]TWP Marketing[/eluser]
@Philtem
[quote author="PhilTem" date="1343074487"]I don't have a clue yet about what is causing the error. However, I was just stumbling over this line when reading through the OP's code

Code:
$this->table = ('languages');
[/quote]

I would guess this is a typo, maybe done with copy/paste.

@Iaxus Could you check the code you posted in your first post and make sure this line is correct?




Theme © iAndrew 2016 - Forum software by © MyBB