title: Yii2 Basic display create from from another model to a view from another model
body: <p>I create a CRUD called Channel and a CRUD Post, so I want to add create Post form to DetailView of Channel; example when a user view Channel Alpha under the Alpha details he have a form from Post to create a Post inside that Channel</p>
  
  <p>user can view the detail of a Channel and also can add Post to that Channel</p>
  
  <p>something similar to :</p>
  
  <p>in Channel controller </p>
  
  <pre><code>public function actionView($id)
      {
          $ly_addPost = new Posts();
          return $this-&gt;render('view', [
              'model' =&gt; $this-&gt;findModel($id),
              'addpost' =&gt; $ly_addPost,
          ]);
      }
  </code></pre>
  
  <p>and in channel view I did edit it to :</p>
  
  <p>//Yii2 code </p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\widgets\DetailView;
  use yii\widgets\ActiveForm;
  /* @var $this yii\web\View */
  /* @var $model app\models\Channel */
  
  $this-&gt;title = $model-&gt;Channel_name;
  $this-&gt;params['breadcrumbs'][] = ['label' =&gt; 'Channels', 'url' =&gt; ['index']];
  $this-&gt;params['breadcrumbs'][] = $this-&gt;title;
  ?&gt;
  &lt;div class="channel-view"&gt;
  
      &lt;h1&gt;&lt;?= Html::encode($this-&gt;title) ?&gt;&lt;/h1&gt;
  
      &lt;p&gt;
          &lt;?= Html::a('Update', ['update', 'id' =&gt; $model-&gt;Channel_id], ['class' =&gt; 'btn btn-primary']) ?&gt;
          &lt;?= Html::a('Delete', ['delete', 'id' =&gt; $model-&gt;Channel_id], [
              'class' =&gt; 'btn btn-danger',
              'data' =&gt; [
                  'confirm' =&gt; 'Are you sure you want to delete this item?',
                  'method' =&gt; 'post',
              ],
          ]) ?&gt;
      &lt;/p&gt;
      &lt;div class="col-md-12"&gt;
          &lt;?= $this-&gt;render ('_form', [
              'addpost' =&gt; $ly_addPost,
          ])
          ?&gt;
  
          &lt;div class="posts-form"&gt;
  
              &lt;?php $form = ActiveForm::begin(); ?&gt;
  
              &lt;?= $form-&gt;field($model, 'Posts_title')-&gt;textInput(['maxlength' =&gt; true]) ?&gt;
  
              &lt;?= $form-&gt;field($model, 'Posts_text')-&gt;textInput(['maxlength' =&gt; true]) ?&gt;
  
              &lt;?= $form-&gt;field($model, 'Posts_file')-&gt;textInput(['maxlength' =&gt; true]) ?&gt;
  
              &lt;?php //= $form-&gt;field($model, 'Posts_crdate')-&gt;textInput() ?&gt;
  
              &lt;?= $form-&gt;field($model, 'Channel_id')-&gt;textInput(['maxlength' =&gt; true]) ?&gt;
  
              &lt;?= $form-&gt;field($model, 'Permissions_id')-&gt;textInput() ?&gt;
  
              &lt;?php //= $form-&gt;field($model, 'user_id')-&gt;textInput() ?&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;?= Html::submitButton($model-&gt;isNewRecord ? 'Create' : 'Update', ['class' =&gt; $model-&gt;isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?&gt;
              &lt;/div&gt;
  
              &lt;?php ActiveForm::end(); ?&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>but I get error : </p>
  
  <p>PHP Notice – yii\base\ErrorException</p>
  
  <p>Undefined variable: ly_addPost</p>