/**
  * Updates an existing Books model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $authors = new Authors();
     if ($model->saveChanges()) {
         return $this->redirect(Yii::$app->request->post('referrer'));
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', ['model' => $this->findModel($id), 'authors' => $authors]);
     }
     return $this->render('update', ['model' => $this->findModel($id), 'authorsList' => $authors->getAuthorsFullnamesList(), 'referrer' => $this->getReferrer()]);
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Authors::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname]);
     return $dataProvider;
 }
Пример #3
0
    $searchModel->dateFrom = Yii::$app->formatter->asDate($searchModel->dateFrom);
    $searchModel->dateTo = Yii::$app->formatter->asDate($searchModel->dateTo);
} else {
    $searchModel->dateFrom = null;
    $searchModel->dateTo = null;
}
?>

<?php 
$form = yii\bootstrap\ActiveForm::begin(['method' => 'get', 'action' => ['books/index']]);
?>

<div>
    <div style="width: 30%; float: left">
    <?php 
echo $form->field($searchModel, 'author_id')->dropDownList(ArrayHelper::map(models\Authors::find()->all(), 'id', 'fullName'), ['prompt' => 'автор'])->label(false);
?>
    </div>
    <div style="width: 30%; float: left">
        <?php 
echo $form->field($searchModel, 'name')->label(false)->textInput(['placeholder' => 'Название книги']);
?>
    </div>
    <div style="clear: both"></div>
    <div>
        <div style="width: 30%; float: left">
            <?php 
echo $form->field($searchModel, 'dateFrom')->widget(DatePicker::classname(), ['language' => 'ru'])->label(false)->textInput(['placeholder' => 'Дата выхода c']);
?>
        </div>
        <div style="width: 30%; float: left">
Пример #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthor()
 {
     return $this->hasOne(Authors::className(), ['id' => 'author_id']);
 }
Пример #5
0
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\BooksSearch */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="books-search">

    <?php 
$form = ActiveForm::begin(['action' => ['index'], 'method' => 'get', 'options' => ['data-pjax' => '1']]);
?>

    <div class="row">
        <div class="col-md-4">
            <?php 
echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(\common\models\Authors::find()->all(), 'id', 'fullName'), ['prompt' => '--Автор--']);
?>
        </div>
        <div class="col-md-8">
            <?php 
echo $form->field($model, 'name');
?>
        </div>
    </div>

    <div class="row">
        <div class="col-md-2 text-search">
                Дата выхода книги:
        </div>
        <div class="col-md-2">
            <?php 
Пример #6
0
?>
</code>.
</p>


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

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

<?php 
echo $form->field($model, 'date')->widget(\yii\jui\DatePicker::classname(), ['language' => 'ru'])->textInput(['placeholder' => 'Дата выхода']);
?>

<?php 
echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Authors::find()->all(), 'id', 'fullName'), ['prompt' => 'автор']);
echo $form->field($model, 'preview')->fileInput();
?>


<div class="form-group">
    <?php 
echo Html::submitButton('update', ['class' => 'btn btn-primary', 'name' => 'update-button']);
?>
</div>

<?php 
ActiveForm::end();
Пример #7
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.');
     }
 }