我正在为一些有趣的项目工作,但我现在被困住了。每次我调用 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);
}
}