Yii下拉框、计数器、下载文件
原文:http://www.gulianqiang.com/57.html
1.利用yii制作下拉菜单:
<?php echo $form->dropDownList($model,'category',array('key1'=>'value1','key2'=>'value2')); ?>
2.使用updateCounters来更新计数器字段
Book::model()->updateCounters(array('download_count'=>1),':id=id',array(':id'=>$id));
3. ,使用sendFile()来下载文件。
$type = LFilter::checkString($_GET['t']);
$dataProvider = Book::model()->findByPk($id);
$content = $this->renderPartial('book',array(
'dataProvider' => $dataProvider,
'type' => $type,
),true,false);
Yii::app()->request->sendFile($dataProvider->name.'.'.$type,$content);
}
4. findAll()的使用;
$params=array(
'select'=>'id,name,image',
'order'=>'total_point DESC',
'limit'=>5,
);
$this->findAll($params);