Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii如何使用相关表格进行搜索_Php_Yii - Fatal编程技术网

Php Yii如何使用相关表格进行搜索

Php Yii如何使用相关表格进行搜索,php,yii,Php,Yii,我无法在搜索表单中将类别与产品组合。谢谢 public function search() { // @todo Please modify the following code to remove attributes that should not be searched. $criteria=new CDbCriteria; $criteria->compare('id',$this->id); $cri

我无法在搜索表单中将类别与产品组合。谢谢

public function search()
    {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria=new CDbCriteria;
        $criteria->compare('id',$this->id);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('short_description',$this->short_description,true);
        $criteria->compare('long_description',$this->long_description,true);
        $criteria->compare('stars',$this->stars);
        $criteria->compare('image',$this->image,true);
        $criteria->compare('price',$this->price);
        $criteria->compare('discount_price',$this->discount_price);
        $criteria->compare('count_orders',$this->count_orders);
        $criteria->with = array('categories');
        $criteria->compare('categories.id',$this->parent_cat, true);
        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }


<fieldset>
        <label>
            <div class="col-md-3">
                <?php echo $form->label($model->parent_cat,'parent_cat'); ?>
            </div>
            <div class="col-md-3">
                <?php echo $form->dropDownList($model,'parent_cat', CHtml::listData(Categories::model()->findAll(), 'parent_cat', 'name')); ?>
            </div>
        </label>
    </fieldset>


return array(
            'categories'=>array(self::BELONGS_TO, 'Categories', 'parent_cat'),
        );
$criteria->compare('parent_cat',$this->parent_cat);

<div class="col-md-3">
<?php 
  $Categories = Categories::model()->findAll();
  $listData = CHtml::listData($Categories,'id','name');
  $listData[0] = "Категория продукта";
  ksort($listData);
  echo $form->dropDownList($model,'parent_cat',$listData, array('class'=>'form-  control','options' => array($model->parent_cat=>array('selected'=>true)))); 
?>
</div>