Hello,
I have created a table called posts and linked the posts table to the user table with a author_id foreign key.
I have also created a controller, model and crud for the posts page.
In the posts page I would like to have the user id passed in the form in the _form.php view file automatically without inputting it myself by hand. How to do this please?
All I am trying to do is get the user id inside the form so it is stored in the grid for that user.
Here is the _form.php code:
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\models\Posts */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="posts-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'posts_title')->textInput(['maxlength' => 100]) ?>
<?= $form->field($model, 'posts_description')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'author_id')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
Thank you,
Ben