-1

我正在为一些有趣的项目工作,但我现在被困住了。每次我调用 index.php 时,我都会收到通知和致命错误。

Notice: Undefined variable: translator in C:\xampp\htdocs\Curve\manage\pages\menu.sfwp on line 309

Fatal error: Call to a member function getText() on a non-object in C:\xampp\htdocs\Curve\manage\pages\menu.sfwp on line 309

我需要所有文件并打电话给我的班级。

结构:index.php -> core/core.inc.php -> classes/Translator.cs.php index.php -> pages/menu.sfwp

核:

if(corekey != "STR456512013213280935405CMS"){
    die();
}
//Sessionn
session_start();

//MySQL Connection
try{
    $conn = new PDO("mysql:host=localhost;dbname=Curve", 'root', '');
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $Exception){
    throw new Exception( $Exception->getMessage( ) , $Exception->getCode( ) );
}

//classes
require('classes/General.cs.php');
require('classes/Users.cs.php');
require('classes/Portal.cs.php');
require('classes/Translation.cs.php');

$users          = new users($conn);
$general        = new general($conn);
$portal         = new portal($conn);
$templatePortal = new portalTemplate($conn);
$translator     = new Translator($conn);

菜单.sfwp

<?php $translator->getTxt(1, $_SESSION['lang']); ?> 

翻译器.cs.php

class Translator
{
    private $db;

    public function __construct($database) {
        $this->db = $database;
    }

    private function getTxt($text, $userlang){
        $lang = "lang_".$userlang;
        $query = $this->db->prepare("SELECT * FROM ".$lang." WHERE id='".$text."'");
        $query->execute();
        $row = $query->fetch();
        echo($row->text);
    }
}
4

3 回答 3

0

Menu.sfwp您尝试调用getText不存在的方法时。
你的Translator班级有getTxt方法。
这是一个错字。

Menu.wfwp应该是这样的:

<?php $translator->getTxt(1, $_SESSION['lang']); ?> 
于 2013-10-11T10:59:25.053 回答
0

你的 Menu.sfwp 应该有

<?php 
   $translator     = new Translator($conn);
   $translator->getText(1, $_SESSION['lang']);
?> 

还要检查 getTxt 的拼写。

于 2013-10-11T11:03:47.843 回答
0

require_once('classes/Translation.cs.php');在 Menu.sfwp 中使用

<?php 
$translator=new Translator($conn);

$translator->getText(1, $_SESSION['lang']); 

?> 
于 2013-10-11T10:52:05.463 回答