public function init() { parent::init(); if ($this->id) { /** @var \common\models\Sound $sound */ $sound = \common\models\Sound::findOne($this->id); if ($sound && ($sound->public || Yii::$app->user->can('member'))) { $this->_sound = $sound; } } else { throw new InvalidParamException(Yii::t('front', 'No required parameter given') . ' - id'); } }
/** * Returns sound items for CKEditor sound plugin * @return array */ public function actionSoundItems() { $items = ArrayHelper::map(Sound::find()->all(), 'title', 'id'); $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; $response->data = $items; return $response; }