class UserScore extends CComponent
{
private $score = 0;
public function __construct($score)
{
$this->score = $score;
}
public function init($score)
{
$this->score = $score;
}
public function loadScore()
{
return $this->score;
}
}
the problem is that when i try to construct class like below it returns error :
CWebApplication and its behaviors do not have a method or closure named "UserScore".
$this->beginWidget('bootstrap.widgets.CGridView', array(
'id'=>'users-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array(
'name'=>'realScore',
'value'=>'Yii::app()->UserScore(10)->loadScore', //try to construct with value 10 for score
)
));
class UserScore extends CApplicationComponent
{
private $score = 0;
public function setScore($score)
{
$this->score = $score;
return $this; //important for using 'chained'
}
You have to install the application component in config/main.php
'components' =>array(
...
'userScore'=>'UserScore',
//or if you want to assign more options like a default score
'userScore'=>array(
'class'=>'UserScore',
'score'=>20,
...
)
...
)