dongxuan1660 2015-07-15 18:08 采纳率: 100%
浏览 43
已采纳

为什么这条线会破坏我的页面?

My PHP file starts out with

<?php

$tm = new TeamManager();

?>

<script type="text/javascript">
    var team = <?php echo json_encode($tm->GetWholeTeam()); ?>;
</script>

and the rest isn't being read, for reasons unknown. I've narrowed it down to the line <?php echo json_encode($tm->GetWholeTeam()); ?> but no errors are showing even if I add

error_reporting(-1);
ini_set('display_errors', 'On'); 

to the top of the script. For reference, my TeamManager class is defined in

<?php

// Gets included in functions.php


final class MySqlInfo
{

    const TEAMTABLENAME = 'mems';
    const PROJSTABLENAME = 'projs';

    public static function getTeamTableName ( )
    {
        return self::TEAMTABLENAME;
    }

    public static function getProjectsTableName ( )
    {
        return self::PROJSTABLENAME;
    }
}

final class MethodResult
{

    public $succeeded; 
    public $message; 

    public function MethodResult ( $succeededInit = NULL, $messageInit = NULL )
    {
        $this->$succeeded = $succeededInit;
        $this->$message = $messageInit;
    }   

}

final class TeamMember 
{
    public $name; // team member name
    public $title; // team member title
    public $bio; // team member bio
    public $sord; // team member sort order
    public $picfn; // team member profile picture file name

    public function TeamMember ( $name_init, $title_init, $bio_init, $sord_init, $picfn_init )
    {
        $this->name = $name_init; 
        $this->title = $title_init;
        $this->bio = $bio_init;
        $this->sord = $sord_init;
        $this->picfn = $picfn_init;
    }
}

final class TeamManager
{

    public function TeamManager ( )
    {
        // ....
    }

    public function addMember ( TeamMember $M )
    {

        $q = "INSERT INTO " . MySqlInfo::TEAMTABLENAME . " (" . implode( ',', array($M->name, $M->title, $M->bio, $M->sord, $M->picfn) ) . ") VALUES ('" . implode('\',\'', array($_POST['fullname'], $_POST['title'], $_POST['bio'], $_POST['sord'], $targetFileName)) . "')";
        // ^ query for inserting member M to the database

        if (!$wpdb->query($q))
        {
            return new MethodResult(false, 'Query to insert new team member failed');
        }
        // else
        return new MethodResult(true, 'Successfully added new member' . $M->name);
    }

    public function getWholeTeam ( )
    {
        $q = "SELECT name,title,bio,sord,picfn FROM " . MySqlInfo::TEAMTABLENAME;
        $teamRows = $wpdb->query($q);
        return $teamRows; 
    }
}

?>

but I am not getting any errors on that page either. I've also run everything through an online PHP validator and do not get any errors. What gives?

  • 写回答

2条回答 默认 最新

  • duanjiati1755 2015-07-15 18:41
    关注

    Variable scope:

        $teamRows = $wpdb->query($q);
                    ^^^^^
    

    That is undefined within your getWholeTeam() method (and in all the methods that use it, in fact) You need a

     global $wpdb;
    

    in there.

    You should have AT LEAST gotten an undefined variable warning on $wpdb and a fatal error for "calling member function on non-object". That suggests you've got all debug options turned off: you need to enable error_logging and display_errors when you're debugging. They should never be off in the first place on a devel system.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line