1
$columnToChange = $this->getColumnName($questionNo); //Gets EXAMHIST_Q2_JUGDGE
    $conn = Propel::getConnection(ExamHistoryPeer::DATABASE_NAME);
        //Update the approriate question with user answer in exam history table;
        $selectCriteria = new Criteria();   
        $selectCriteria->add(ExamHistoryPeer::EXAM_HISTORY_ID, $examHist->getExamHistoryId());
        $updateCriteria = new Criteria();   
        //This shows fatal error
        $updateCriteria->add(ExamHistoryPeer::$columnToChange, $userAnswer); 
        //$updateCriteria->add(ExamHistoryPeer::EXAMHIST_Q2_JUGDGE, $userAnswer); //This works
        BasePeer::doUpdate($selectCriteria, $updateCriteria, $conn);

致命错误:访问未声明的静态属性:ExamHistoryPeer::$columnToChange

你们中的任何一个,请告诉我为什么这不能工作,以及如何使它与 ExamHistoryPeer::$columnToChange 一起工作

4

2 回答 2

1

PHP 认为您想要获得不恒定的静态属性。这是因为$登录ExamHistoryPeer::$columnToChange

而是使用constant('ExamHistoryPeer::columnToChange')来获取该常量的值。

于 2013-10-11T10:32:01.130 回答
0

你也许可以这样做?

$oReflection = new ReflectionClass(ExamHistoryPeer);

//Value of the Constant
$mValue = $oReflection->getConstant($columnToChange);
于 2013-10-11T10:52:31.873 回答