Subversion-Projekte lars-tiefland.cakephp

Revision

Revision 14 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
5 lars 1
<?php
2
 
3
    //$Id$
4
 
5
    /**
6
     * @author Lars Tiefland <tiefland@weban.de>
7
     * @copyright 2009 Webagentur Niewerth
8
     * @package Cakephp
9
     * @version $Rev$
10
     * @license propietary
11
     * @filesource
12
     *
13
     */
14
 
15
    /**
16
     *
17
     * @author Lars Tiefland <tiefland@weban.de>
18
     * @copyright 2009 Webagentur Niewerth
19
     * @package Cakephp
20
     */
21
 
22
    class PostsController extends AppController
23
    {
24
 
25
        var $name = 'Posts';
26
 
27
        function index()
28
        {
29
            $this->set( 'posts', $this->Post->find('all') );
30
        }
9 lars 31
        function view( $id = null )
32
        {
33
            $this->Post->id = $id;
34
            $this->set( 'post', $this->Post->read() );
35
        }
11 lars 36
        function add()
37
        {
38
            if ( ! empty($this->data) )
39
            {
40
                if ( $this->Post->save($this->data) )
41
                {
42
                    $this->Session->setFlash( 'Your post has been saved.' );
43
                    $this->redirect( array('action' => 'index') );
44
                }
45
            }
46
        }
14 lars 47
        function delete( $id )
48
        {
49
            $this->Post->del( $id );
50
            $this->Session->setFlash( 'The post with id: ' . $id .
51
                ' has been deleted.' );
52
            $this->redirect( array('action' => 'index') );
53
        }
15 lars 54
 
55
        function edit( $id = null )
56
        {
57
            $this->Post->id = $id;
58
            if ( empty($this->data) )
59
            {
60
                $this->data = $this->Post->read();
61
            }
62
            else
63
            {
64
                if ( $this->Post->save($this->data) )
65
                {
66
                    $this->Session->setFlash( 'Your post has been updated.' );
67
                    $this->redirect( array('action' => 'index') );
68
                }
69
            }
70
        }
5 lars 71
    }
72
 
73
?>