douzhicui2209 2014-04-17 12:34
浏览 36

yii中未定义的变量模型

I am getting the error undefined variable model. I have the following codes in my view and controller. My aim is to search the results and show it in same page. I have tried the following things but its not working.

Again,I this this the conventional yii method to do so,or do I have to use a search() function from model SearchEmployee().?

public function actionSearch()
{
      $model = new SearchEmployee();

       /*Getting Data From Search Form For Processing */
  if (isset($_POST['SearchEmployee'])) {

      $category   =  $_POST['SearchEmployee']['category_id'];
      $skills     =  $_POST['SearchEmployee']['skills'];
      $experience =  $_POST['SearchEmployee']['experience'];

      $model = SearchEmployee::model()->find(array(
      'select' => array('*'), "condition" => "category_id=$category AND key_skills like '%$skills%' AND experience=$experience",
      ));

      $this->render('search',$model);
  }

  /*Getting Data From Search Form For Processing */
  $this->render('search', array('model' => $model));
}

In View Section: search.php//To display and search the desired result

<div class="row">
   <?php echo $form->labelEx($model,'Category'); ?>
   <?php echo $form->dropDownList($model,'category_id',$list,array('empty' =>'(Select a Category')); ?>
   <?php echo $form->error($model,'category'); ?>
</div>

  <div class="row">
<?php echo $form->labelEx($model,'Experience'); ?>
    <?php echo $form->textField($model,'experience'); ?>
    <?php echo $form->error($model,'experience'); ?>    
</div>


<div class="row buttons">
  <?php echo CHtml::submitButton('Search'); ?>
</div>



<div class="view">

  <h1>Results </h1>

  <div class="view" id="id">

     <h1> Records Display </h1>

     <h4>Name:        <?php echo $form->labelEx($model,'name'); ?></h4>
     <h4>Skills:      <?php echo $form->labelEx($model,'experience'); ?></h4>
     <h4>Experience:  <?php echo $form->labelEx($model,'skills'); ?></h4>
     <h5>&nbsp;&nbsp ;<?php echo $form->labelEx('VIew Details'); ?></h5>
   </div>

 </div>

In view section I am using the search and view results option in the same form.I am getting the error after clicking the search button.Is this the correct way to do

  • 写回答

2条回答 默认 最新

  • doutangkao2789 2014-04-17 12:45
    关注

    Remove this line:

    $this->render('search',$model);
    

    First it's invalid because it should be:

    $this->render('search', array('model' => $model));
    

    But also it's unnecessary because you already have it lower in your code.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题