Skip to content

Commit

Permalink
Adding redirect() if deletion fails.
Browse files Browse the repository at this point in the history
Fixing formatting.
  • Loading branch information
markstory committed Jun 7, 2009
1 parent 4d7f005 commit 5e5293a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
26 changes: 16 additions & 10 deletions cake/console/libs/templates/objects/controller_actions.ctp
Expand Up @@ -30,9 +30,9 @@
if (!$id) { if (!$id) {
<?php if ($wannaUseSession): ?> <?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('Invalid <?php echo $singularHumanName ?>', true)); $this->Session->setFlash(__('Invalid <?php echo $singularHumanName ?>', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action' => 'index'));
<?php else: ?> <?php else: ?>
$this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action'=>'index')); $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
<?php endif; ?> <?php endif; ?>
} }
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id)); $this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
Expand All @@ -45,9 +45,9 @@
if ($this-><?php echo $currentModelName; ?>->save($this->data)) { if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
<?php if ($wannaUseSession): ?> <?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true)); $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action' => 'index'));
<?php else: ?> <?php else: ?>
$this->flash(__('<?php echo $currentModelName; ?> saved.', true), array('action'=>'index')); $this->flash(__('<?php echo $currentModelName; ?> saved.', true), array('action' => 'index'));
<?php endif; ?> <?php endif; ?>
} else { } else {
<?php if ($wannaUseSession): ?> <?php if ($wannaUseSession): ?>
Expand Down Expand Up @@ -77,18 +77,18 @@
if (!$id && empty($this->data)) { if (!$id && empty($this->data)) {
<?php if ($wannaUseSession): ?> <?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('Invalid <?php echo $singularHumanName; ?>', true)); $this->Session->setFlash(__('Invalid <?php echo $singularHumanName; ?>', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action' => 'index'));
<?php else: ?> <?php else: ?>
$this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action'=>'index')); $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
<?php endif; ?> <?php endif; ?>
} }
if (!empty($this->data)) { if (!empty($this->data)) {
if ($this-><?php echo $currentModelName; ?>->save($this->data)) { if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
<?php if ($wannaUseSession): ?> <?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true)); $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action' => 'index'));
<?php else: ?> <?php else: ?>
$this->flash(__('The <?php echo $singularHumanName; ?> has been saved.', true), array('action'=>'index')); $this->flash(__('The <?php echo $singularHumanName; ?> has been saved.', true), array('action' => 'index'));
<?php endif; ?> <?php endif; ?>
} else { } else {
<?php if ($wannaUseSession): ?> <?php if ($wannaUseSession): ?>
Expand Down Expand Up @@ -122,15 +122,21 @@
$this->Session->setFlash(__('Invalid id for <?php echo $singularHumanName; ?>', true)); $this->Session->setFlash(__('Invalid id for <?php echo $singularHumanName; ?>', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
<?php else: ?> <?php else: ?>
$this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action'=>'index')); $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
<?php endif; ?> <?php endif; ?>
} }
if ($this-><?php echo $currentModelName; ?>->del($id)) { if ($this-><?php echo $currentModelName; ?>->del($id)) {
<?php if ($wannaUseSession): ?> <?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('<?php echo $singularHumanName; ?> deleted', true)); $this->Session->setFlash(__('<?php echo $singularHumanName; ?> deleted', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
<?php else: ?> <?php else: ?>
$this->flash(__('<?php echo $singularHumanName; ?> deleted', true), array('action'=>'index')); $this->flash(__('<?php echo $singularHumanName; ?> deleted', true), array('action' => 'index'));
<?php endif; ?> <?php endif; ?>
} }
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('<?php echo $singularHumanName; ?> was not deleted', true));
<?php else: ?>
$this->flash(__('<?php echo $singularHumanName; ?> was not deleted', true), array('action' => 'index'));
<?php endif; ?>
$this->redirect(array('action' => 'index'));
} }
6 changes: 3 additions & 3 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -318,21 +318,21 @@ function testBakeActionsWithNoSessions() {
$this->assertTrue(strpos($result, "\$this->set('articles', \$this->paginate());") !== false); $this->assertTrue(strpos($result, "\$this->set('articles', \$this->paginate());") !== false);


$this->assertTrue(strpos($result, 'function view($id = null)') !== false); $this->assertTrue(strpos($result, 'function view($id = null)') !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('Invalid Article', true), array('action'=>'index'))") !== false); $this->assertTrue(strpos($result, "\$this->flash(__('Invalid Article', true), array('action' => 'index'))") !== false);
$this->assertTrue(strpos($result, "\$this->set('article', \$this->Article->read(null, \$id)") !== false); $this->assertTrue(strpos($result, "\$this->set('article', \$this->Article->read(null, \$id)") !== false);


$this->assertTrue(strpos($result, 'function add()') !== false); $this->assertTrue(strpos($result, 'function add()') !== false);
$this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false); $this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false); $this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('The Article has been saved.', true), array('action'=>'index'))") !== false); $this->assertTrue(strpos($result, "\$this->flash(__('The Article has been saved.', true), array('action' => 'index'))") !== false);


$this->assertTrue(strpos($result, 'function edit($id = null)') !== false); $this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
$this->assertTrue(strpos($result, "\$this->Article->Tag->find('list')") !== false); $this->assertTrue(strpos($result, "\$this->Article->Tag->find('list')") !== false);
$this->assertTrue(strpos($result, "\$this->set(compact('tags'))") !== false); $this->assertTrue(strpos($result, "\$this->set(compact('tags'))") !== false);


$this->assertTrue(strpos($result, 'function delete($id = null)') !== false); $this->assertTrue(strpos($result, 'function delete($id = null)') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->del($id))') !== false); $this->assertTrue(strpos($result, 'if ($this->Article->del($id))') !== false);
$this->assertTrue(strpos($result, "\$this->flash(__('Article deleted', true), array('action'=>'index'))") !== false); $this->assertTrue(strpos($result, "\$this->flash(__('Article deleted', true), array('action' => 'index'))") !== false);
} }


/** /**
Expand Down

0 comments on commit 5e5293a

Please sign in to comment.