~tsep-dev/tsep/0.9-beta

« back to all changes in this revision

Viewing changes to branches/symfony/cake/console/templates/default/actions/controller_actions.ctp

  • Committer: geoffreyfishing
  • Date: 2011-01-11 23:46:12 UTC
  • Revision ID: svn-v4:ae0de26e-ed09-4cbe-9a20-e40b4c60ac6c::125
Created a symfony branch for future migration to symfony

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Bake Template for Controller action generation.
 
4
 *
 
5
 * PHP versions 4 and 5
 
6
 *
 
7
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 
8
 * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
 
9
 *
 
10
 * Licensed under The MIT License
 
11
 * Redistributions of files must retain the above copyright notice.
 
12
 *
 
13
 * @copyright     Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
 
14
 * @link          http://cakephp.org CakePHP(tm) Project
 
15
 * @package       cake
 
16
 * @subpackage    cake.console.libs.template.objects
 
17
 * @since         CakePHP(tm) v 1.3
 
18
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 
19
 */
 
20
?>
 
21
 
 
22
        function <?php echo $admin ?>index() {
 
23
                $this-><?php echo $currentModelName ?>->recursive = 0;
 
24
                $this->set('<?php echo $pluralName ?>', $this->paginate());
 
25
        }
 
26
 
 
27
        function <?php echo $admin ?>view($id = null) {
 
28
                if (!$id) {
 
29
<?php if ($wannaUseSession): ?>
 
30
                        $this->Session->setFlash(__('Invalid <?php echo strtolower($singularHumanName) ?>', true));
 
31
                        $this->redirect(array('action' => 'index'));
 
32
<?php else: ?>
 
33
                        $this->flash(__('Invalid <?php echo strtolower($singularHumanName); ?>', true), array('action' => 'index'));
 
34
<?php endif; ?>
 
35
                }
 
36
                $this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
 
37
        }
 
38
 
 
39
<?php $compact = array(); ?>
 
40
        function <?php echo $admin ?>add() {
 
41
                if (!empty($this->data)) {
 
42
                        $this-><?php echo $currentModelName; ?>->create();
 
43
                        if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
 
44
<?php if ($wannaUseSession): ?>
 
45
                                $this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved', true));
 
46
                                $this->redirect(array('action' => 'index'));
 
47
<?php else: ?>
 
48
                                $this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.', true), array('action' => 'index'));
 
49
<?php endif; ?>
 
50
                        } else {
 
51
<?php if ($wannaUseSession): ?>
 
52
                                $this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.', true));
 
53
<?php endif; ?>
 
54
                        }
 
55
                }
 
56
<?php
 
57
        foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
 
58
                foreach ($modelObj->{$assoc} as $associationName => $relation):
 
59
                        if (!empty($associationName)):
 
60
                                $otherModelName = $this->_modelName($associationName);
 
61
                                $otherPluralName = $this->_pluralName($associationName);
 
62
                                echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
 
63
                                $compact[] = "'{$otherPluralName}'";
 
64
                        endif;
 
65
                endforeach;
 
66
        endforeach;
 
67
        if (!empty($compact)):
 
68
                echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
 
69
        endif;
 
70
?>
 
71
        }
 
72
 
 
73
<?php $compact = array(); ?>
 
74
        function <?php echo $admin; ?>edit($id = null) {
 
75
                if (!$id && empty($this->data)) {
 
76
<?php if ($wannaUseSession): ?>
 
77
                        $this->Session->setFlash(__('Invalid <?php echo strtolower($singularHumanName); ?>', true));
 
78
                        $this->redirect(array('action' => 'index'));
 
79
<?php else: ?>
 
80
                        $this->flash(sprintf(__('Invalid <?php echo strtolower($singularHumanName); ?>', true)), array('action' => 'index'));
 
81
<?php endif; ?>
 
82
                }
 
83
                if (!empty($this->data)) {
 
84
                        if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
 
85
<?php if ($wannaUseSession): ?>
 
86
                                $this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved', true));
 
87
                                $this->redirect(array('action' => 'index'));
 
88
<?php else: ?>
 
89
                                $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.', true), array('action' => 'index'));
 
90
<?php endif; ?>
 
91
                        } else {
 
92
<?php if ($wannaUseSession): ?>
 
93
                                $this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.', true));
 
94
<?php endif; ?>
 
95
                        }
 
96
                }
 
97
                if (empty($this->data)) {
 
98
                        $this->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
 
99
                }
 
100
<?php
 
101
                foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
 
102
                        foreach ($modelObj->{$assoc} as $associationName => $relation):
 
103
                                if (!empty($associationName)):
 
104
                                        $otherModelName = $this->_modelName($associationName);
 
105
                                        $otherPluralName = $this->_pluralName($associationName);
 
106
                                        echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
 
107
                                        $compact[] = "'{$otherPluralName}'";
 
108
                                endif;
 
109
                        endforeach;
 
110
                endforeach;
 
111
                if (!empty($compact)):
 
112
                        echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
 
113
                endif;
 
114
        ?>
 
115
        }
 
116
 
 
117
        function <?php echo $admin; ?>delete($id = null) {
 
118
                if (!$id) {
 
119
<?php if ($wannaUseSession): ?>
 
120
                        $this->Session->setFlash(__('Invalid id for <?php echo strtolower($singularHumanName); ?>', true));
 
121
                        $this->redirect(array('action'=>'index'));
 
122
<?php else: ?>
 
123
                        $this->flash(sprintf(__('Invalid <?php echo strtolower($singularHumanName); ?>', true)), array('action' => 'index'));
 
124
<?php endif; ?>
 
125
                }
 
126
                if ($this-><?php echo $currentModelName; ?>->delete($id)) {
 
127
<?php if ($wannaUseSession): ?>
 
128
                        $this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted', true));
 
129
                        $this->redirect(array('action'=>'index'));
 
130
<?php else: ?>
 
131
                        $this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted', true), array('action' => 'index'));
 
132
<?php endif; ?>
 
133
                }
 
134
<?php if ($wannaUseSession): ?>
 
135
                $this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted', true));
 
136
<?php else: ?>
 
137
                $this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted', true), array('action' => 'index'));
 
138
<?php endif; ?>
 
139
                $this->redirect(array('action' => 'index'));
 
140
        }
 
 
b'\\ No newline at end of file'