我无法将另一个函数的值发送到yii中的另一个函数。这两个函数都在同一个文件中,一个模型在yii中。下面是代码。
public function totalPointsValue($userId) {
$value = Yii::app()->db->createCommand()
->select('sum(totalPoints) as pointsSum')
->from('fndn_UserTotal')
->where('userId =:id', array(':id'=>$userId))
//->where('userId = ' . $userId)
->queryRow();
$totalPoints = $value['pointsSum'];
}
public function checkEligable(){
totalPointsValue($userId);
error_log(print_r($totalPoints, true), 3, 'debug.log');
}
是否可以将totalPointsValue()中的值发送到checkEligable()?
答案 0 :(得分:0)
尝试:
public function totalPointsValue($userId) { $value = Yii::app()->db->createCommand() ->select('sum(totalPoints) as pointsSum') ->from('fndn_UserTotal') ->where('userId =:id', array(':id'=>$userId)) //->where('userId = ' . $userId) ->queryRow(); return $value['pointsSum']; } public function checkEligable(){ $totalPoints = $this->totalPointsValue($userId); error_log(print_r($totalPoints, true), 3, 'debug.log'); }
或checkEligable的另一个变体:
public function checkEligable(){ $totalPoints = self::model()->totalPointsValue($userId); // OR $totalPoints = self::totalPointsValue($userId); // if totalPointsValue made static error_log(print_r($totalPoints, true), 3, 'debug.log'); }
答案 1 :(得分:0)
尝试以下代码
public function totalPointsValue($userId)
{
$value = Yii::app()->db->createCommand()
->select('sum(totalPoints) as pointsSum')
->from('fndn_UserTotal')
->where('userId =:id', array(':id'=>$userId))
//->where('userId = ' . $userId)
->queryRow();
$totalPoints = $value['pointsSum'];
}
public function checkEligable()
{
ModelName::model()->totalPointsValue($userId);
error_log(print_r($totalPoints, true), 3, 'debug.log');
}