How to show results of model on another view

I’m new to Yii framework and am not advanced in PHP but I know what I’m doing. I have a view with activeForm and its model is requesting student information from a database. So I wanted to render the student view on another view and that works, however, when I submit the form it does not show the results at all. The page just refresh and go back to its normal state as if I didn’t enter any input.

How can I solve this problem? Can anyone help and point me in a right direction? I just need to show the results on the other view, that’s it!

Here’s my code:

//-- Student View –

<div class="row">

    <div class="span6">

        <div class="ms_form">

            <?php $form = ActiveForm::begin(['options' => ['class' => 'form-vertical'], 'id' => 'student_form']) ?>

              <label>Staff Look Up:</label>

                <p style=""><?= Html::a("Employees", ['site/staffinfo'], ['class' => 'msoe-submit-button']) ?></p>


            <p><strong>Enter the following to check status:</strong></p>

            <?= $form->field($model, 'firstName') ?>

            <?= $form->field($model, 'lastName') ?>

            <?= $form->field($model, 'jenzId') ?>

            <?= Html::submitButton('Look Up', ['class' => 'ms-submit-button']) ?>

            <?php $form->end() ?>





<div class="row">


if (!empty($firstnames)) {


    <div class="span12">

        <h3>Student Standings</h3>

         <table width="100%">

              <tr style="background:#ebebeb; border: 1px solid #ccc;">

                <th>ID Number</th>

                <th>Full Names</th>

                <th>Last Name</th>

                <th>Current Degree</th>                

                <th>Student Standing</th>


                <th>Recent Year Enrolled</th>


               <tr style="border:1px solid #ccc; margin-bottom:20px;">

                <td><?= $firstnames['JenzabarID'] ?> </td>

                <td style="border-left:1px solid #ccc;"><?= $firstnames['First Name'] ?> </td>

                <td style="border-left:1px solid #ccc;"><?= $firstnames['Last Name'] ?> </td>

                <td style="border-left:1px solid #ccc;"><?= $firstnames['Current Degree'] ?> </td>

                <td style="border-left:1px solid #ccc;"><?= $firstnames['Student Standing'] ?></td>

                <td style="border-left:1px solid #ccc;"><?= $firstnames['Major'] ?> </td>

                <td style="border-left:1px solid #ccc;"><?= $firstnames['Recent Year Enrolled'] ?> </td>




// – Model –

 public function findFirstnames()


        $query = new Query();

                $query ->select('nm.id_num as JenzabarID,

                nm.first_name as [First Name],

                nm.last_name as [Last Name],

                dh.div_cde as [Current Degree],

                    (Case sm.current_class_cde

                       When \'AV\' then \'Not Found\'

                       When \'BS\' then \'BS Graduate\'

                       When \'C\' then \'Certificate\'

                       when \'FR\' then \'Freshman\'

                       when \'GR\' then \'Graduate\'

                       when \'JR\' then \'Junior\'

                       when \'MS\' then \'MS Graduate\'

                       when \'ND\' then \'Non-Degree\'

                       when \'NM\' then \'Non-Matriculated\'

                       when \'SO\' then \'Sophomore\'

                       when \'SR\' then \'Senior\'

                       Else \'Unknown\'

                    End) as [Student Standing]

// – Controller –

    public function actionStaffinfo()


        $firstname = false;

        $model = new staffinfo();

        if (!empty($_POST)) {


            if ($model->validate()) {

                $firstname = $model->findFirstname();



        return $this->render('staff-index', ['model' => $model, 'firstname' => $firstname]);


Below is how I rendered the student view on another view but it does not show results.

// – Faculty View –

<div class="row">


  <div id="studentDetails" class="span12">

    [b]<!-- Here's the Partial view in Faculty -->[/b]

    <?= Yii::$app->controller->renderPartial('index', ['model'=>$model]) ?>

    </div> <!--staff end --> 

     <div id="staffDetails" class="span12">

      <h2>Search Form - Staff Laptop</h2>

      <div class="msoe_form"><!-- STUDENT FORM -->

            <?php $form = ActiveForm::begin(['options' => ['class' => 'form-vertical'], 'id' => 'staff_form']) ?> 

            <p><strong>Enter the following to check status:</strong></p>

            <?= $form->field($model, 'firstName') ?>

            <?= $form->field($model, 'lastName') ?>

            <?= Html::submitButton('Look Up', ['class' => 'msoe-submit-button']) ?>

            <?php $form->end() ?>

            </div> <br>

      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. 

        Morbi vitae tristique neque. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. 

        Nunc tincidunt lectus quis arcu imperdiet rutrum. 

        Vestibulum mattis erat ac lacus placerat efficitur. Quisque et orci in augue auctor dictum eleifend eu turpis.</p>


    </div>  <!--student end -->

</div><!-- row end -->

Which view is staff-index, which one is index?

You pass firstname to one view, you’re testing for firstnames in one view. (And you don’t propagate firstname to the partial.)


I have two functions, namely: firstname is in staffinfo model for staff-index view and firstnames is in student model for index view. So I did add renderPartial thinking that it would also show the results. I’m not familiar with partials and still learning this framework and MVC.

Example of renderPartial usage.

Hi tri,

The idea here is to retrieve information of each student or staff after submitting the form not the whole list. So I want to stress that both models and views works fine separately but I want to do renderpartial because I to have the students and staff search under one URL and not redirect to another page. I tried the example you gave but got a syntax error on findAll()

I think the problem I have is to load the results of student model on the staff view.

Please see attached screenshot of the students results as separate page (view) and the error.

You didn’t answer this question

But never mind. On a closer look it seems like you’re using Yii 2 but this is the Yii 1.1 forum section. My renderPartial example was just to show the parameter passing.

You may want to start a new topic in the Yii 2 section. Please give better info about what you are trying to accomplish, including names of models, controllers and views used. Do not include unneccessary parts like "loren ipsum …" and excessive view/query content.