/**
  * Displays a single Books model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     // id автора
     $book = Books::find()->where(['id' => $id])->one();
     $author_id = $book->author_id;
     // ФИО автора по id
     $author = Authors::find()->where(['id' => $author_id])->one();
     $author = $author->lastname . " " . $author->firstname;
     return $this->render('view', ['author' => $author, 'model' => $this->findModel($id)]);
 }
Beispiel #2
0
    echo Html::encode($this->title);
    ?>
</h1>
    <?php 
    // echo $this->render('_search', ['model' => $searchModel]);
    ?>

    <p>
        <?php 
    echo Html::a('Create Books', ['create'], ['class' => 'btn btn-success']);
    ?>
    </p>

<!--
        //$image = (new Query)->select('id','preview')->from('books');
-->

    <?php 
    echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'filter' => false], ['attribute' => 'name', 'filter' => false], ['attribute' => 'date_create', 'value' => 'date_create', 'format' => 'raw', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'date_create', 'dateFormat' => 'yyyy-MM-dd'])], ['attribute' => 'date_update', 'value' => 'date_update', 'format' => 'raw', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'date_update', 'dateFormat' => 'yyyy-MM-dd'])], 'preview' => ['attribute' => 'preview', 'label' => 'Превью', 'format' => 'raw', 'value' => function ($model) {
        return '<a href="http://test.onlysites.ru/yii-advanced/frontend' . $model->preview . '" class="fancybox"><img src="http://test.onlysites.ru/yii-advanced/frontend' . $model->preview . '" width="150" /></a>';
    }, 'filter' => false], ['attribute' => 'date', 'value' => 'date', 'format' => 'raw', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'date', 'dateFormat' => 'yyyy-MM-dd'])], ['format' => 'raw', 'attribute' => 'author_id', 'value' => function ($model) {
        $author = Authors::find()->where(['id' => $model->author_id])->one();
        $author = $author->lastname . " " . $author->firstname;
        return $author;
    }, 'filter' => Html::activeDropDownList($searchModel, 'author_id', ArrayHelper::map(Authors::find()->asArray()->all(), 'id', 'firstname'), ['class' => 'form-control', 'prompt' => ' Выберите автора '])], ['class' => 'yii\\grid\\ActionColumn']]]);
    ?>
    <?php 
}
?>
</div>
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthor()
 {
     return $this->hasOne(Authors::className(), ['id' => 'author_id']);
 }
<div class="books-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'id')->textInput();
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Authors::find()->all(), 'id', 'firstname'), ['prompt' => '[ Выберите имя автора ]']);
?>

    <?php 
echo $form->field($model, 'file')->fileInput();
?>
    <?php 
echo $form->field($model, 'date')->widget(DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd']);
?>
    
    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>