public function gettagsAction() { $this->view->disable(); if ($this->request->isAjax()) { if (isset($_GET['q']) && ($keyword = trim($_GET['q'])) !== '') { $tags = \Models\Tags::suggestTags($keyword); if ($tags !== array()) { //echo implode("\n", $tags); echo \Helpers\CJSON::encode($tags); } } } }
public function editAction($id = null) { $this->assets->addCss('css/select2.css'); $this->assets->addJs('js/select2.js'); if (!$this->request->isPost() && !$this->request->isAjax()) { $id = $this->filter->sanitize($id, array("int")); $model = $this->loadModel($id); if (!$model) { $this->flashSession->error("Новость не найдена"); $this->response->redirect("backend/posts/index"); } $this->view->setVar("id", $model->id); $this->view->setVar('tags', \Models\Tags::getTagsForSelect()); Tag::displayTo("id", $model->id); Tag::displayTo("title", $model->title); Tag::displayTo("body", $model->body); Tag::displayTo("status", $model->status); Tag::displayTo("tags", $model->tags); } elseif ($this->request->isPost() && !$this->request->isAjax()) { $auth = $this->session->get('auth'); if (!$auth) { return $this->response->redirect(); } $id = $this->request->getPost('id', 'int'); $model = $this->loadModel($id); if (!$model) { $this->flashSession->error("Ничего не найдено"); $this->response->redirect("backend/posts/index"); } $model->author_id = $auth['id']; if (!$model->update($_POST)) { foreach ($model->getMessages() as $message) { $this->flashSession->error((string) $message->getMessage()); //echo var_dump($message->getType()); //echo var_dump($message->getMessage()); } return $this->response->redirect('backend/posts/edit/' . $model->id); } else { $this->flashSession->success("Запись удачно обновлена"); return $this->response->redirect("backend/posts"); } } }
protected function afterDelete() { \Models\Tags::updateFrequency($this->tags, ''); }
public static function getTagsForSelect() { $names = array(); $tags = \Models\Tags::find(); $tags->setHydrateMode(\Phalcon\Mvc\Model\Resultset::HYDRATE_OBJECTS); if ($tags->count()) { foreach ($tags as $tag) { $names[$tag->id] = $tag->name; } //return \Helpers\CJSON::encode($names); return $names; } }