0

我希望每次调用函数 actionNewAnswer 时,计数器都会增加。但是现在,计数器总是 2。怎么了?

public function actionNewAnswer(){     
    static $count = 1;
    ++$count;

    $modelAntwoorden = $this->loadModelAntwoorden();

    $this->renderPartial('_formAnswer', array(
        'model' => new VraagAntwoord(), 
        'counter' => $count,
        'modelAntwoorden'=>$modelAntwoorden,
    ),false,true);  
}
4

1 回答 1

1

actionNewAnswer()一次对服务器的请求只调用一次,下次它是新的

1、添加到配置

'cache' => 'CFileCache'

2、在Controller类中添加const

const myStaticCount = 'myStaticCount';

3、添加到actionNewAnswer

$count = 0; // comment for zero +1
if (Yii::app()->cache->offsetExists(self::myStaticCount)) {
    $count = Yii::app()->cache->get(self::myStaticCount);
}
Yii::app()->cache->set(self::myStaticCount, ++$count);
于 2012-11-17T16:32:48.837 回答