/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return User the loaded model * @throws CHttpException */ public function loadAdverts($id) { $model = Adverts::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
static function getCategories() { // поставить кэширование запроса и обработку fields $categories = Yii::app()->db->createCommand('SELECT * FROM category')->queryAll(); $ret_cat = array(); foreach ($categories as $n => $cat) { $ret_cat[$cat['id']] = $cat; $ret_cat[$cat['id']]['fields'] = json_decode($cat['fields'], true); if (is_array($ret_cat[$cat['id']]['fields'])) { foreach ($ret_cat[$cat['id']]['fields'] as $f_n => $field) { if ($field['type'] == 2) { $ret_cat[$cat['id']]['fields'][$f_n]['atr'] = explode(",", $field['atr']); } } } } $cat_count = Yii::app()->db->createCommand()->select('category_id, COUNT(*) count')->from(Adverts::model()->tableName())->group('category_id')->query(); foreach ($cat_count as $row) { $ret_cat[$row['category_id']]['count'] = $row['count']; } return $ret_cat; }
public function actionBan($id) { $model = $this->loadModel($id); $model->status = USER::STATUS_BANNED; $model->update(array('status')); //$adv_model = new Adverts(); $adv_model = Adverts::model()->find("user_id = :id ", array(':id' => intval($id))); if ($adv_model) { $adv_model->delete(); } $this->redirect(array('/')); }
/** * Вывод главной * отличается наличием виджета категорий вверху */ public function actionIndex() { $roots = Category::model()->roots()->findAll(); $criteria = new CDbCriteria(); $criteria->limit = 10; $criteria->order = 'id desc'; $IndexAdv = Adverts::model()->findAll($criteria); $this->render('index', array( 'roots' => $roots, 'IndexAdv' => $IndexAdv, )); }