Beispiel #1
0
 /**
  * Displays a single Books model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $book = $this->findModel($id)->attributes;
     $author = Authors::findOne($book["author_id"]);
     $book["author"] = $author->attributes;
     header('Content-Type: application/json');
     echo json_encode($book, JSON_UNESCAPED_UNICODE);
     /*
     echo $book->name;
     echo $book->date_create;
     echo $book->date_update;
     echo $book->preview;
     */
 }
Beispiel #2
0
 /**
  * Finds the Authors model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Authors the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Authors::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #3
0
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a('Удалить', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Вы уверены, что хотите удалить книгу?', 'method' => 'post']]);
?>
    </p>



    <?php 
$attributes = ['name', 'date_create', 'date_update'];
if (!empty($model->preview)) {
    $path = Yii::getAlias('@webroot' . $model->preview);
    if (file_exists($path)) {
        $size = getimagesize($path);
        $attributes[] = ['attribute' => 'preview', 'format' => 'raw', 'value' => Html::a(Html::img($model->preview, ['width' => $size[0], 'height' => $size[1]]), str_replace('preview', 'images', $model->preview), ['rel' => 'fancybox'])];
    }
}
$author = Authors::findOne($model->author_id);
$attributes = array_merge($attributes, ['date', ['attribute' => 'author_id', 'format' => 'raw', 'value' => $author->firstname . ' ' . $author->lastname]]);
echo DetailView::widget(['model' => $model, 'attributes' => $attributes]);
?>

</div>