好的,我得到了类文件,其中有函数-
var $text;
public function languages()
{
if (isset($_GET['lang']) && $_GET['lang'] != '')
{
$_SESSION['lang'] = $_GET['lang'];
}
switch($_SESSION['lang'])
{
case 'en_EN': require_once('language/lang.eng.php');break;
case 'lv_LV': require_once('language/lang.lv.php');break;
case 'ru_RU': require_once('language/lang.ru.php');break;
default: require_once('language/lang.eng.php');
}
$this->text = $text;
}
public function translate($txt)
{
if(isset($this->text[$txt]))
{
return $this->text[$txt];
}
}如果我像这样通过index.php进行翻译-> echo $index->translate('search');,它可以进行翻译,但如果我在类文件中进行翻译,例如-
if ($country_rows > 0)
{
$_SESSION['country'] = $_GET['country'];
}
else
{
$_SESSION['country'] = $this->translate('all_countries');
}
}
if ($_SESSION['country'] == '')
{
$_SESSION['country'] = $this->translate('all_countries');
}它没有显示出来。在index.php头中,我包含了-
require_once('class.index.php');
$index = new index;
$index->get_country();
$index->languages();可能的问题是什么,我如何修复它,这样我也可以翻译类文件中的所有内容?感谢您的帮助!
发布于 2011-10-06 23:15:22
第一个猜测:没有会话开始?
session_start();第二个猜测:假设您在另一个类中使用translate,您应该首先初始化对象,在下面的示例中,我将translate类传递给var $index;
<?
include_once('class.index.php');
class myClass {
var $index;
public function __construct() {
$index = new index();
$index->get_country();
$index->languages();
$this->index = $index;
}
public function yourFunction() {
echo $this->index->translate('all_countries');
print_r($this->index);
}
}
?>https://stackoverflow.com/questions/7676106
复制相似问题