/** * Returns the static model of the specified AR class. * Please note that you should have this exact method in all your CActiveRecord descendants! * @param integer $restaurants_id restaurant ID. * @return restaurant array */ public function getTablesByRestaurantId($restaurants_id = null) { if (!$restaurants_id) { return array('status' => 0, 'message' => 'Invalid Restaurant.'); } $criteria = new CDbCriteria(); $criteria->condition = 'restaurants_id = :restaurants_id'; $criteria->order = 'id ASC'; $criteria->params = array(':restaurants_id' => $restaurants_id); $item_count = RestaurantTables::model()->count($criteria); $dataProvider = new CActiveDataProvider('RestaurantTables', array('criteria' => $criteria, 'pagination' => array('pagesize' => 10))); return array('status' => 1, 'result' => $dataProvider); }
/** * Manage Tables */ public function actionTables() { $model = new RestaurantTables('addTable'); if (isset($_POST['RestaurantTables'])) { $_POST['RestaurantTables']['created_date'] = date('Y-m-d H:i:s'); $_POST['RestaurantTables']['modified_date'] = date('Y-m-d H:i:s'); $model->attributes = $_POST['RestaurantTables']; if ($model->validate()) { $result = $model->addTable(); } else { // echo "<pre>"; print_r($model->getErrors()); exit(); } $this->redirect(array('tables')); } $tables = $model->getTablesByRestaurantId(Yii::app()->user->getId()); $this->render('tables', array('model' => $model, 'tables' => $tables['result'])); }