/app/Controller/TagsController.php
PHP | 98 lines | 60 code | 6 blank | 32 comment | 13 complexity | dcd4d7158a061f45c5f06cc14847ca79 MD5 | raw file
- <?php
- /**
- * Tags Controller
- *
- */
- class TagsController extends AppController {
- /**
- * index method
- *
- * @return void
- */
- public function index() {
- $this->Tag->recursive = 0;
- $this->set('tags', $this->paginate());
- }
- /**
- * view method
- *
- * @param string $id
- * @return void
- */
- public function view($id = null) {
- $this->Tag->id = $id;
- if (!$this->Tag->exists()) {
- throw new NotFoundException(__('Invalid tag'));
- }
- $this->set('tag', $this->Tag->read(null, $id));
- }
- /**
- * add method
- *
- * @return void
- */
- public function add() {
- if ($this->request->is('post')) {
- $this->Tag->create();
- if ($this->Tag->save($this->request->data)) {
- $this->Session->setFlash(__('The tag has been saved'));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The tag could not be saved. Please, try again.'));
- }
- }
- $articles = $this->Tag->Article->find('list');
- $this->set(compact('articles'));
- }
- /**
- * edit method
- *
- * @param string $id
- * @return void
- */
- public function edit($id = null) {
- $this->Tag->id = $id;
- if (!$this->Tag->exists()) {
- throw new NotFoundException(__('Invalid tag'));
- }
- if ($this->request->is('post') || $this->request->is('put')) {
- if ($this->Tag->save($this->request->data)) {
- $this->Session->setFlash(__('The tag has been saved'));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The tag could not be saved. Please, try again.'));
- }
- } else {
- $this->request->data = $this->Tag->read(null, $id);
- }
- $articles = $this->Tag->Article->find('list');
- $this->set(compact('articles'));
- }
- /**
- * delete method
- *
- * @param string $id
- * @return void
- */
- public function delete($id = null) {
- if (!$this->request->is('post')) {
- throw new MethodNotAllowedException();
- }
- $this->Tag->id = $id;
- if (!$this->Tag->exists()) {
- throw new NotFoundException(__('Invalid tag'));
- }
- if ($this->Tag->delete()) {
- $this->Session->setFlash(__('Tag deleted'));
- $this->redirect(array('action'=>'index'));
- }
- $this->Session->setFlash(__('Tag was not deleted'));
- $this->redirect(array('action' => 'index'));
- }
- }