-2

我无法将值从另一个函数发送到 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() ?

4

2 回答 2

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');
}
于 2013-10-22T07:15:03.303 回答
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');
}
于 2013-10-22T07:16:56.907 回答