Exemplo n.º 1
1
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     $models = Yii::$app->getModule('vote')->models;
     foreach ($models as $value) {
         $modelId = Rating::getModelIdByName($value);
         $modelName = Rating::getModelNameById($modelId);
         Event::on($modelName::className(), $modelName::EVENT_INIT, function ($event) {
             if (null === $event->sender->getBehavior('rating')) {
                 $event->sender->attachBehavior('rating', ['class' => RatingBehavior::className()]);
             }
         });
     }
 }
Exemplo n.º 2
0
 public function testGetModelNameById()
 {
     $firstModelName = Rating::getModelNameById($this->firstModelId);
     $this->assertEquals($firstModelName, $this->firstModelName);
     $secondModelName = Rating::getModelNameById($this->secondModelId);
     $this->assertEquals($secondModelName, $this->secondModelName);
     $thirdModelName = Rating::getModelNameById($this->thirdModelId);
     $this->assertEquals($thirdModelName, $this->thirdModelName);
 }