/** * Performs a delete on given scaffolded Model. * * @param array $params Parameters for scaffolding * @return mixed Success on delete, error if delete fails * @access private */ function __scaffoldDelete($params = array()) { if ($this->controller->_beforeScaffold('delete')) { if (isset($params['pass'][0])) { $id = $params['pass'][0]; } elseif ($this->_validSession) { $this->controller->Session->setFlash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey))); $this->controller->redirect($this->redirect); } else { return $this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)), '/' . Inflector::underscore($this->controller->viewPath)); } if ($this->ScaffoldModel->delete($id)) { if ($this->_validSession) { $this->controller->Session->setFlash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id)); $this->controller->redirect($this->redirect); } else { return $this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath); } } else { if ($this->_validSession) { $this->controller->Session->setFlash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id)); $this->controller->redirect($this->redirect); } else { return $this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath); } } } elseif ($this->controller->_scaffoldError('delete') === false) { return $this->__scaffoldError(); } }
/** * Performs a delete on given scaffolded Model. * * @param array $params Parameters for scaffolding * @return mixed Success on delete, error if delete fails */ protected function _scaffoldDelete(CakeRequest $request) { if ($this->controller->_beforeScaffold('delete')) { if (!$request->is('post')) { throw new MethodNotAllowedException(); } $id = false; if (isset($request->params['pass'][0])) { $id = $request->params['pass'][0]; } $this->ScaffoldModel->id = $id; if (!$this->ScaffoldModel->exists()) { throw new NotFoundException(__('Invalid %s', Inflector::humanize($this->modelClass))); } if ($this->ScaffoldModel->delete()) { $message = __('The %1$s with id: %2$d has been deleted.', Inflector::humanize($this->modelClass), $id); return $this->_sendMessage($message); } else { $message = __('There was an error deleting the %1$s with id: %2$d', Inflector::humanize($this->modelClass), $id); return $this->_sendMessage($message); } } elseif ($this->controller->_scaffoldError('delete') === false) { return $this->_scaffoldError(); } }
/** * Performs a delete on given scaffolded Model. * * @param array $params * @return success on delete error if delete fails * @access private */ function __scaffoldDelete($params = array()) { if ($this->controllerClass->_beforeScaffold('delete')) { $id = $params['pass'][0]; if ($this->controllerClass->{$this->modelKey}->del($id)) { if (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) { $this->controllerClass->Session->setFlash('The ' . Inflector::humanize($this->modelKey) . ' with id: ' . $id . ' has been deleted.'); $this->controllerClass->redirect('/' . Inflector::underscore($this->controllerClass->viewPath)); } else { return $this->controllerClass->flash('The ' . Inflector::humanize($this->modelKey) . ' with id: ' . $id . ' has been deleted.', '/' . Inflector::underscore($this->controllerClass->viewPath)); } } else { if (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) { $this->controllerClass->Session->setFlash('There was an error deleting the ' . Inflector::humanize($this->modelKey) . ' with the id ' . $id); $this->controllerClass->redirect('/' . Inflector::underscore($this->controllerClass->viewPath)); } else { return $this->controllerClass->flash('There was an error deleting the ' . Inflector::humanize($this->modelKey) . ' with the id ' . $id, '/' . Inflector::underscore($this->controllerClass->viewPath)); } } } elseif ($this->controllerClass->_scaffoldError('delete') === false) { return $this->__scaffoldError(); } }
/** * testToBeInheritedGuardmethods method * * @access public * @return void */ function testToBeInheritedGuardmethods() { $Controller = new Controller(); $this->assertTrue($Controller->_beforeScaffold('')); $this->assertTrue($Controller->_afterScaffoldSave('')); $this->assertTrue($Controller->_afterScaffoldSaveError('')); $this->assertFalse($Controller->_scaffoldError('')); }
/** * testToBeInheritedGuardmethods method * * @access public * @return void */ function testToBeInheritedGuardmethods() { $request = new CakeRequest('controller_posts/index'); $Controller = new Controller($request); $this->assertTrue($Controller->_beforeScaffold('')); $this->assertTrue($Controller->_afterScaffoldSave('')); $this->assertTrue($Controller->_afterScaffoldSaveError('')); $this->assertFalse($Controller->_scaffoldError('')); }