使用updateCounters()来更新计数器字段:
Book::model()->updateCounters(array('download_count'=>1),':id=id',array(':id'=>$id)); |
使用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); |
设计数据库时候如果create_time,update_time字段为int(10).在模型中使用行为插件:
public function behaviors() { return array( 'CTimestampBehavior' => array( 'class' => 'zii.behaviors.CTimestampBehavior', 'createAttribute' => 'create_time', 'updateAttribute' => 'update_time', ) ); } |