| 16591 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Bake Template for Controller action generation.
|
|
|
4 |
*
|
|
|
5 |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
6 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
7 |
*
|
|
|
8 |
* Licensed under The MIT License
|
|
|
9 |
* For full copyright and license information, please see the LICENSE.txt
|
|
|
10 |
* Redistributions of files must retain the above copyright notice.
|
|
|
11 |
*
|
|
|
12 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
13 |
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
14 |
* @package Cake.Console.Templates.default.actions
|
|
|
15 |
* @since CakePHP(tm) v 1.3
|
|
|
16 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
17 |
*/
|
|
|
18 |
?>
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* <?php echo $admin ?>index method
|
|
|
22 |
*
|
|
|
23 |
* @return void
|
|
|
24 |
*/
|
|
|
25 |
public function <?php echo $admin ?>index() {
|
|
|
26 |
$this-><?php echo $currentModelName ?>->recursive = 0;
|
|
|
27 |
$this->set('<?php echo $pluralName ?>', $this->Paginator->paginate());
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* <?php echo $admin ?>view method
|
|
|
32 |
*
|
|
|
33 |
* @throws NotFoundException
|
|
|
34 |
* @param string $id
|
|
|
35 |
* @return void
|
|
|
36 |
*/
|
|
|
37 |
public function <?php echo $admin ?>view($id = null) {
|
|
|
38 |
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
|
|
|
39 |
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
|
|
40 |
}
|
|
|
41 |
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
|
|
|
42 |
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->find('first', $options));
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
<?php $compact = array(); ?>
|
|
|
46 |
/**
|
|
|
47 |
* <?php echo $admin ?>add method
|
|
|
48 |
*
|
|
|
49 |
* @return void
|
|
|
50 |
*/
|
|
|
51 |
public function <?php echo $admin ?>add() {
|
|
|
52 |
if ($this->request->is('post')) {
|
|
|
53 |
$this-><?php echo $currentModelName; ?>->create();
|
|
|
54 |
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
|
|
55 |
<?php if ($wannaUseSession): ?>
|
|
|
56 |
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
|
|
|
57 |
return $this->redirect(array('action' => 'index'));
|
|
|
58 |
} else {
|
|
|
59 |
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
|
|
60 |
<?php else: ?>
|
|
|
61 |
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
|
|
|
62 |
<?php endif; ?>
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
<?php
|
|
|
66 |
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
|
|
|
67 |
foreach ($modelObj->{$assoc} as $associationName => $relation):
|
|
|
68 |
if (!empty($associationName)):
|
|
|
69 |
$otherModelName = $this->_modelName($associationName);
|
|
|
70 |
$otherPluralName = $this->_pluralName($associationName);
|
|
|
71 |
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
|
|
|
72 |
$compact[] = "'{$otherPluralName}'";
|
|
|
73 |
endif;
|
|
|
74 |
endforeach;
|
|
|
75 |
endforeach;
|
|
|
76 |
if (!empty($compact)):
|
|
|
77 |
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
|
|
|
78 |
endif;
|
|
|
79 |
?>
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
<?php $compact = array(); ?>
|
|
|
83 |
/**
|
|
|
84 |
* <?php echo $admin ?>edit method
|
|
|
85 |
*
|
|
|
86 |
* @throws NotFoundException
|
|
|
87 |
* @param string $id
|
|
|
88 |
* @return void
|
|
|
89 |
*/
|
|
|
90 |
public function <?php echo $admin; ?>edit($id = null) {
|
|
|
91 |
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
|
|
|
92 |
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
|
|
93 |
}
|
|
|
94 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
95 |
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
|
|
96 |
<?php if ($wannaUseSession): ?>
|
|
|
97 |
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
|
|
|
98 |
return $this->redirect(array('action' => 'index'));
|
|
|
99 |
} else {
|
|
|
100 |
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
|
|
101 |
<?php else: ?>
|
|
|
102 |
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
|
|
|
103 |
<?php endif; ?>
|
|
|
104 |
}
|
|
|
105 |
} else {
|
|
|
106 |
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
|
|
|
107 |
$this->request->data = $this-><?php echo $currentModelName; ?>->find('first', $options);
|
|
|
108 |
}
|
|
|
109 |
<?php
|
|
|
110 |
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
|
|
|
111 |
foreach ($modelObj->{$assoc} as $associationName => $relation):
|
|
|
112 |
if (!empty($associationName)):
|
|
|
113 |
$otherModelName = $this->_modelName($associationName);
|
|
|
114 |
$otherPluralName = $this->_pluralName($associationName);
|
|
|
115 |
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
|
|
|
116 |
$compact[] = "'{$otherPluralName}'";
|
|
|
117 |
endif;
|
|
|
118 |
endforeach;
|
|
|
119 |
endforeach;
|
|
|
120 |
if (!empty($compact)):
|
|
|
121 |
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
|
|
|
122 |
endif;
|
|
|
123 |
?>
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* <?php echo $admin ?>delete method
|
|
|
128 |
*
|
|
|
129 |
* @throws NotFoundException
|
|
|
130 |
* @param string $id
|
|
|
131 |
* @return void
|
|
|
132 |
*/
|
|
|
133 |
public function <?php echo $admin; ?>delete($id = null) {
|
|
|
134 |
$this-><?php echo $currentModelName; ?>->id = $id;
|
|
|
135 |
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
|
|
136 |
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
|
|
137 |
}
|
|
|
138 |
$this->request->allowMethod('post', 'delete');
|
|
|
139 |
if ($this-><?php echo $currentModelName; ?>->delete()) {
|
|
|
140 |
<?php if ($wannaUseSession): ?>
|
|
|
141 |
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'));
|
|
|
142 |
} else {
|
|
|
143 |
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be deleted. Please, try again.'));
|
|
|
144 |
}
|
|
|
145 |
return $this->redirect(array('action' => 'index'));
|
|
|
146 |
<?php else: ?>
|
|
|
147 |
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'), array('action' => 'index'));
|
|
|
148 |
} else {
|
|
|
149 |
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
|
150 |
}
|
|
|
151 |
<?php endif; ?>
|
|
|
152 |
}
|