public function addAction() { $params = $this->_request['params']; $this->view->input = array(); if ($this->isPost()) { // Save thumbnail $uploadFile = new Core_Helper_Upload(); $configs['uploadPath'] = BASE_PATH . '/public/upload/images/'; $configs['allowedTypes'] = 'gif|jpg|jpeg|png'; $config['maxSize'] = '2'; $configs['overwrite'] = false; $configs['removeSpaces'] = true; $uploadFile->initialize($configs); $uploadFile->doUpload('thumbnail'); if ($err = $uploadFile->getErrors()) { $this->view->errors = array('thumbnail' => array_shift($err)); $this->view->input = $this->_request['params']; } else { $categoryArr = array_filter($this->view->categories, create_function('$obj', 'return $obj->id == ' . $params['subcategory'] . ';')); $params['category'] = array_shift($categoryArr); // Save post $postModel = new Post_Model_Post(); $postModel->initialize($params); $postModel->save(); // Save input tags $tagModel = new Tag_Model_Tag(); $postTagModel = new Tag_Model_PostTag(); $tagModel->insertTags($params['tags'], $postModel->lastInsertId, $postTagModel); $this->redirect(array('route' => 'route_admin_post')); } } }
public function suggestAction() { $params = $this->_request['params']; $tagModel = new Tag_Model_Tag(); $tags = $tagModel->fetchAll('name', 'WHERE slug LIKE :slug', array(':slug' => '%' . Base_Helper_String::generateSlug($params['term']) . '%')); $data = array(); foreach ($tags as $tag) { $data[]['label'] = $tag->name; } $this->_noRender = true; echo json_encode($data); }