bookmarks /app/controllers/links_controller.php

Language PHP Lines 68
MD5 Hash 3a8f9060b76aaf5462d51e638e0570f2
Repository https://github.com/hardsshah/bookmarks.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
class LinksController extends AppController {

    var $name = 'Links';
    var $helpers = array('Html', 'Form');
    var $viewPath = '_templates';
    var $paginate = array('limit' => 20);

    function index() {
        $this->Link->recursive = 0;
        $this->set('links', $this->paginate());
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid Link.', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->set('link', $this->Link->read(null, $id));
    }

    function add() {
        if (!empty($this->data)) {
            $this->Link->create();
            if ($this->Link->save($this->data)) {
                $this->Session->setFlash(__('The Link has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Link could not be saved. Please, try again.', true));
            }
        }
        $linkCategories = $this->Link->LinkCategory->find('list');
        $this->set(compact('linkCategories'));
    }

    function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid Link', true));
            $this->redirect(array('action'=>'index'));
        }
        if (!empty($this->data)) {
            if ($this->Link->save($this->data)) {
                $this->Session->setFlash(__('The Link has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Link could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Link->read(null, $id);
        }
        $linkCategories = $this->Link->LinkCategory->find('list');
        $this->set(compact('linkCategories'));
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for Link', true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->Link->del($id)) {
            $this->Session->setFlash(__('Link deleted', true));
            $this->redirect(array('action'=>'index'));
        }
    }

}
?>
Back to Top