/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Users(); $account = new Account(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Users'])) { $model->attributes = $_POST['Users']; // save avatar $model->Avatar = CUploadedFile::getInstance($model, 'Avatar'); if (!empry($model->Avatar)) { $model->Avatar->saveAs(Yii::getPathOfAlias('webroot') . '/images/avatars/' . $model->Avatar->name); } if ($model->save()) { $this->redirect(array('view', 'id' => $model->ID)); } } $this->render('create', array('model' => $model, 'account' => $account)); }
function add_short_filter($field, $expression) { if (empry($expression)) { return; } preg_match('/^(o|c|\\!|\\*)?(.*)$/', $expression, $matches); $parms = $matches[0]; $operator = empty($parms[0]) ? "=" : $parms[0]; $values = empty($parms[1]) ? "" : $parms[1]; $this->add_filter($field, $operator, $values); }
function json_prep($data, $extras = FALSE) { //header('Cache-Control: no-cache, must-revalidate'); //header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); switch ($this->alt) { case 'json': header('Content-type: application/json'); break; default: //header('Content-type: application/json'); break; } if (!empty($data['errors'])) { // Contains error if (!empry($this->callback)) { print_r($this->callback . '(' . json_encode($data['errors']) . ')'); } else { print_r($this->_indent(json_encode($data['errors']))); } } else { $this->json_result['completed_in'] = number_format(time() - $this->start_time, 3, '.', ''); if (empty($data['results'])) { $this->json_result['results'] = FALSE; $this->json_result['reason'] = "No results"; } else { $this->json_result['results'] = $data['results']; } if (!empty($this->callback)) { print_r($this->callback . '(' . json_encode($this->json_result) . ')'); } else { print_r($this->_indent(json_encode($this->json_result))); } } exit; }