dropdownlist

question…

why i put this coding in file C:\xampp\htdocs\e-frp\protected\views\main\portfolio.php it display error?

<section>

&lt;div class=&quot;input-group&quot;&gt;


    &lt;?= &#036;form-&gt;dropdownList(&#036;User, 'dept_id', Department::model()-&gt;options(), array('class' =&gt; 'form-control')); ?&gt;        


    &lt;div class=&quot;input-group-addon&quot;&gt;&lt;i class=&quot;fa fa-group&quot;&gt;&lt;/i&gt;&lt;/div&gt;


&lt;/div&gt;

</section>


what should i write in file C:\xampp\htdocs\e-frp\protected\controllers\MainController.php at part portfolio?

public function actionPortfolio() {

if (isset(&#036;_POST['submit'])) {


        //create new portfolio data row


		&#036;Department = Department::model()-&gt;findAll();


        &#036;CourseModel = new Course();


        &#036;CourseModel-&gt;module = Yii::app()-&gt;request-&gt;getPost(&quot;programme&quot;);


        &#036;CourseModel-&gt;code = Yii::app()-&gt;request-&gt;getPost(&quot;code&quot;);


		&#036;CourseModel-&gt;name = Yii::app()-&gt;request-&gt;getPost(&quot;coursename&quot;);


        &#036;CourseModel-&gt;user_id = Yii::app()-&gt;user-&gt;profile-&gt;user_id;


        &#036;CourseModel-&gt;save(FALSE);





        &#036;this-&gt;redirect(&quot;portfolio&quot;);


    }





    &#036;this-&gt;render('portfolio', compact(&quot;title&quot;, &quot;CourseModels&quot;));


}

Two things:

  1. What is the error displayed in portfolio.php?

  2. Massive assignment can be done with




$CourseModel->attributes = $_POST['CourseModel'];



if you have in your post data an aggregator variable named ‘CourseModel’.

Fatal error: Call to a member function dropdownList() on a non-object in C:\xampp\htdocs\e-frp\protected\views\main\portfolio.php on line 3

In your view, you haven’t missed ActiveForm begin:




<?php $form = ActiveForm::begin([

    'id' => 'data-form',

]) ?>



that includes all generated html input.

At the end, put




<?php ActiveForm::end() ?>



to end the form object.