public function actionPush() { $model = new Needing(); if (!empty($_POST)) { $model->attributes = $_POST['Needing']; $model->start_time = strtotime($_POST['Needing']['start_time']); $model->end_time = strtotime($_POST['Needing']['end_time']); $model->subject = $_POST['Needing']['subject']; $model->detail = $_POST['detail']; $model->create_time = time(); $model->push_user = '******'; $model->payment = $_POST['Needing']['payment']; $model->save(); } $this->render('push', array('model' => $model)); }
public function actionIndex() { // var_dump($_SERVER);exit; $model = new UserLogin(); $query_arr = array(); if (!empty($_GET['cat_id']) && is_numeric($_GET['cat_id'])) { // array_push($query_arr,array('cat_id'=>$_GET['type'])); $query_arr['cat_id'] = $_GET['cat_id']; } //sql的直接执行,条件可放于query中,防注入 $needing_cat = Yii::app()->db->createCommand("select * from needing_cat")->query()->readAll(); //对cactiverecorde的包装 $criteria = new CDbCriteria(); $criteria->order = 'create_time desc'; if (!empty($_GET['cat_id']) && is_numeric($_GET['cat_id'])) { $criteria->addCondition(array('cat_id=' . $_GET['cat_id'])); } //CActiveDataProvider是基于ActiveRecord实现的一个数据提供者 //needing分页 $page_size = 4; $dataProvider = new CActiveDataProvider('needing', array('pagination' => array('pageSize' => $page_size), 'criteria' => $criteria)); // var_dump($dataProvider->getPagination()); // if(!empty($_GET['action'])&&$_GET['action']=='paging'){ //// echo json_encode($dataProvider->getData(false)); // echo CJSON::encode($dataProvider->getData()); // exit; // } //分页最终处理 if (!empty($query_arr)) { $count = Needing::model()->count("cat_id=:cat_id", $query_arr); } else { $count = Needing::model()->count(); } $page_count = ceil($count / $page_size); $page_now = isset($_GET['Needing_page']) && intval($_GET['Needing_page']) ? $_GET['Needing_page'] : 1; if (!empty($_POST)) { if (!empty($_POST['ajax']) && $_POST['ajax'] == 'denglu') { //失去焦点自动提交ajax请求 echo CActiveForm::validate($model); exit; } else { if (isset($_POST['UserLogin'])) { $model->attributes = $_POST['UserLogin']; // echo $model->getErrors(); if ($model->validate()) { echo 1; } else { echo 0; } Yii::app()->end(); } } } // $model->addError('username','test'); // var_dump($model->getErrors()); $this->render('index', array('model' => $model, 'dataProvider' => $dataProvider, 'page_now' => $page_now, 'count' => $count, 'page_size' => $page_size, 'page_count' => $page_count, 'needing_cat' => $needing_cat, 'query_arr' => $query_arr)); }