Bin will be removed on June 1, 2014 in favor of http://gist.github.com. Please save all your pastes before then. So long, and thanks for all the fish!×
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
<?php
class ClientsController extends AppController
{
    var $name = 'Clients';
    function index()
    {
        $this->set('Clients', $this->Client->find('all'));
    }
    function add()
    {
        if ($this->request->is('post')) {
            if ($this->Client->save($this->request->data)) {
                $this->Session->SetFlash('Client has been saved');
                $this->redirect(array(
                    'action' => 'index'
                ));
            } else {
                $this->Session->setFlash('Nope');
            }
        }
    }
    public function view($id = null)
    {
        $this->Client->id = $id;
        $this->set('Client', $this->Client->read(null, $id));
    }
    public function edit($id = null)
    {
        $this->Client->id = $id;
        if ($this->request->is('get')) {
            $this->request->data = $this->Client->read();
        } else {
            if ($this->Client->save($this->request->data)) {
                $this->Session->setFlash('Client has been updated.');
                $this->redirect(array(
                    'action' => 'index'
                ));
            } else {
                $this->Session->setFlash('Unable to update Client.');
            }
        }
        $this->loadModel('Employee');
        $this->set('Employees', $this->Employee->find('list', array(
            'order' => array(
                'Employee.name'
            )
        )));
        $this->set(compact('Employees'));
    }
    public function delete($id = null)
    {
        if ($this->request->is('/Clients/delete/{id}')) {
            throw new MethodNotAllowedException();
        }
        if ($this->Client->delete($id)) {
            $this->Session->setFlash('The Client with id: ' . $id . ' has been deleted.');
            $this->redirect(array(
                'action' => 'index'
            ));
        }
    }
}
?>