2013-10-22 95 views
-2

我無法從另一個函數發送值到yii中的另一個函數。這兩個函數都在同一個文件裏面,是yii中的Model。下面是代碼。將函數值發送到另一個函數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()?

+1

你的意思就像'totalPointsValue'中的'return $ totalPoints'一樣嗎? – 2013-10-22 07:11:11

回答

0

嘗試:checkEligable的

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'); 
} 

或另一種變體:

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'); 
} 
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'); 
} 
相關問題