$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);
致命错误:访问未声明的静态属性:考试历史记录对等::$columnToChange
你们中的任何一个人,请告诉我为什么这行不通,以及如何让它工作考试历史同行::$columnToChange
PHP 认为你想要的是静态属性而不是常量。这是因为$
登录ExamHistoryPeer::$columnToChange
.
而是使用 constant('ExamHistoryPeer::columnToChange')
来获取该常量的值。
你也许可以这样做?
$oReflection = new ReflectionClass(ExamHistoryPeer);
//Value of the Constant
$mValue = $oReflection->getConstant($columnToChange);