<?php
//echo Yii::$app->basePath;exit;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\widgets\FileInput;
use yii\helpers\ArrayHelper;


/* @var $this yii\web\View */
/* @var $model backend\models\Book */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="book-form">

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

    <?= $form->field($model, 'title')->textInput(['maxlength' => 255]) ?>

    <?= $form->field($model, 'description')->textarea(['rows' => 5]) ?>

    <?= $form->field($model, 'author')->textInput(['maxlength' => 255]) ?>

    <?=
    $form->field($model, 'categoryId')->dropDownList(ArrayHelper::map(\backend\models\Category::find()->all(), 'id', 'title'),array('prompt'=>'Select Category'))
    ?>

    <?= $form->field($model, 'publisher')->textInput(['maxlength' => 255]) ?>
    <?=
        $form->field($model, 'file')->fileInput()
    ?>
    <?php if ($model->id): ?>
        <div class="form-group">
            <?= Html::img(Yii::$app->urlManager->baseUrl . '/images/book/'.$model->image,['width'=>'100']) ?>
        </div>
    <?php endif; ?>
    
    <!--?= $form->field($model, 'file[]')->fileInput(['multiple' => true]) ?-->
    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        &nbsp;<a href="<?php echo \Yii::$app->urlManager->createUrl(['book/index']) ?>" class="btn btn-danger">Back</a>
    </div>

    <?php ActiveForm::end(); ?>

</div>
