mydetails-yii1

1.yii验证码多余的get a new code ,即使在main.php中配置了中文也是出现获取新图片,影响效果
需要把
<?php $this->widget('CCaptcha'); ?>

改成
<?php
$this->widget('CCaptcha',array('showRefreshButton'=>false,'clickableImage'=>true,'imageOptions'=>array('alt'=>'点击换图','title'=>'点击换图','style'=>'cursor:pointer'))); ?>

2.yii提示属性未被定义时,Model中添加了规则,还提示属性未定义,如属性 "Order.formula_id" 未被定义.需要清除缓存Yii::app()->cache->flush();

3.Warning: Invalid argument supplied for foreach.遇到这个问题需要在foreach遍历之前判断要遍历的变量是否是一个数组,if(is_array($info)),否则会报错

4.yii两表关联查询

例如:表soods和表brand,要通过goods_category_id=brand_id 关联goods和brand表

首先:在Goods.php模型文件中
    public function relations(){
        return array(
                'brands'=>array(self::BELONGS_TO, 'Brand', 'goods_brand_id','select'=>'brand_id,brand_name'),
        );
    }

然后: 在goods的控制器GoodsController.php中,

$infos = $goods_model -> findAll(array(
                    'select'=>'goods_id,goods_name,goods_price,goods_category_id,goods_brand_id,goods_number',
                    'condition'=>'goods_brand_id=:brand_id',
                    'order'=>'goods_price desc',
                    'with'=>array('brands'),
                    'params'=>array(':brand_id'=>$brand_id)
            ));
        //    print_r($infos[0]['brands']['brand_name']);exit;

最后:视图文件中,

<td><?php echo $info['brands']['brand_name']?></td>

6.yii下拉框的默认值

在模板文件中,<td><?php echo $form -> dropDownList($goods_model, 'goods_brand_id',CHtml::listData(Brand::model()->findAll(),'brand_id','brand_name'),array('empty'=>'请选择品牌'));?></td>,这样在显示下拉框数据的时候,第一条就是请选择品牌

原文地址:https://www.cnblogs.com/xlz307/p/3822309.html