Skip to content

Commit

Permalink
Changed protected callbacks of scaffold to public in Controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Aug 22, 2011
1 parent f7f3515 commit dbb87a0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 19 deletions.
57 changes: 53 additions & 4 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -1079,32 +1079,68 @@ public function afterFilter() {
* @return boolean Success * @return boolean Success
* @link http://book.cakephp.org/view/984/Callbacks * @link http://book.cakephp.org/view/984/Callbacks
*/ */
public function _beforeScaffold($method) { public function beforeScaffold($method) {
return true; return true;
} }


/**
* Alias to beforeScaffold()
*
* @param string $method
* @return boolean
* @see Controller::beforeScaffold()
* @deprecated
*/
protected function _beforeScaffold($method) {
return $this->beforeScaffold($method);
}

/** /**
* This method should be overridden in child classes. * This method should be overridden in child classes.
* *
* @param string $method name of method called either edit or update. * @param string $method name of method called either edit or update.
* @return boolean Success * @return boolean Success
* @link http://book.cakephp.org/view/984/Callbacks * @link http://book.cakephp.org/view/984/Callbacks
*/ */
public function _afterScaffoldSave($method) { public function afterScaffoldSave($method) {
return true; return true;
} }


/**
* Alias to afterScaffoldSave()
*
* @param string $method
* @return boolean
* @see Controller::afterScaffoldSave()
* @deprecated
*/
protected function _afterScaffoldSave($method) {
return $this->afterScaffoldSave($method);
}

/** /**
* This method should be overridden in child classes. * This method should be overridden in child classes.
* *
* @param string $method name of method called either edit or update. * @param string $method name of method called either edit or update.
* @return boolean Success * @return boolean Success
* @link http://book.cakephp.org/view/984/Callbacks * @link http://book.cakephp.org/view/984/Callbacks
*/ */
public function _afterScaffoldSaveError($method) { public function afterScaffoldSaveError($method) {
return true; return true;
} }


/**
* Alias to afterScaffoldSaveError()
*
* @param string $method
* @return boolean
* @see Controller::afterScaffoldSaveError()
* @deprecated
*/
protected function _afterScaffoldSaveError($method) {
return $this->afterScaffoldSaveError($method);
}

/** /**
* This method should be overridden in child classes. * This method should be overridden in child classes.
* If not it will render a scaffold error. * If not it will render a scaffold error.
Expand All @@ -1114,7 +1150,20 @@ public function _afterScaffoldSaveError($method) {
* @return boolean Success * @return boolean Success
* @link http://book.cakephp.org/view/984/Callbacks * @link http://book.cakephp.org/view/984/Callbacks
*/ */
public function _scaffoldError($method) { public function scaffoldError($method) {
return false; return false;
} }

/**
* Alias to scaffoldError()
*
* @param string $method
* @return boolean
* @see Controller::scaffoldError()
* @deprecated
*/
protected function _scaffoldError($method) {
return $this->scaffoldError($method);
}

} }
22 changes: 11 additions & 11 deletions lib/Cake/Controller/Scaffold.php
Expand Up @@ -158,7 +158,7 @@ public function __construct(Controller $controller, CakeRequest $request) {
* @throws NotFoundException * @throws NotFoundException
*/ */
protected function _scaffoldView(CakeRequest $request) { protected function _scaffoldView(CakeRequest $request) {
if ($this->controller->_beforeScaffold('view')) { if ($this->controller->beforeScaffold('view')) {
if (isset($request->params['pass'][0])) { if (isset($request->params['pass'][0])) {
$this->ScaffoldModel->id = $request->params['pass'][0]; $this->ScaffoldModel->id = $request->params['pass'][0];
} }
Expand All @@ -171,7 +171,7 @@ protected function _scaffoldView(CakeRequest $request) {
Inflector::variable($this->controller->modelClass), $this->request->data Inflector::variable($this->controller->modelClass), $this->request->data
); );
$this->controller->render($this->request['action'], $this->layout); $this->controller->render($this->request['action'], $this->layout);
} elseif ($this->controller->_scaffoldError('view') === false) { } elseif ($this->controller->scaffoldError('view') === false) {
return $this->_scaffoldError(); return $this->_scaffoldError();
} }
} }
Expand All @@ -183,13 +183,13 @@ protected function _scaffoldView(CakeRequest $request) {
* @return mixed A rendered view listing rows from Models database table * @return mixed A rendered view listing rows from Models database table
*/ */
protected function _scaffoldIndex($params) { protected function _scaffoldIndex($params) {
if ($this->controller->_beforeScaffold('index')) { if ($this->controller->beforeScaffold('index')) {
$this->ScaffoldModel->recursive = 0; $this->ScaffoldModel->recursive = 0;
$this->controller->set( $this->controller->set(
Inflector::variable($this->controller->name), $this->controller->paginate() Inflector::variable($this->controller->name), $this->controller->paginate()
); );
$this->controller->render($this->request['action'], $this->layout); $this->controller->render($this->request['action'], $this->layout);
} elseif ($this->controller->_scaffoldError('index') === false) { } elseif ($this->controller->scaffoldError('index') === false) {
return $this->_scaffoldError(); return $this->_scaffoldError();
} }
} }
Expand Down Expand Up @@ -224,7 +224,7 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
$success = __d('cake', 'saved'); $success = __d('cake', 'saved');
} }


if ($this->controller->_beforeScaffold($action)) { if ($this->controller->beforeScaffold($action)) {
if ($action == 'edit') { if ($action == 'edit') {
if (isset($request->params['pass'][0])) { if (isset($request->params['pass'][0])) {
$this->ScaffoldModel->id = $request['pass'][0]; $this->ScaffoldModel->id = $request['pass'][0];
Expand All @@ -240,15 +240,15 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
} }


if ($this->ScaffoldModel->save($request->data)) { if ($this->ScaffoldModel->save($request->data)) {
if ($this->controller->_afterScaffoldSave($action)) { if ($this->controller->afterScaffoldSave($action)) {
$message = __d('cake', $message = __d('cake',
'The %1$s has been %2$s', 'The %1$s has been %2$s',
Inflector::humanize($this->modelKey), Inflector::humanize($this->modelKey),
$success $success
); );
return $this->_sendMessage($message); return $this->_sendMessage($message);
} else { } else {
return $this->controller->_afterScaffoldSaveError($action); return $this->controller->afterScaffoldSaveError($action);
} }
} else { } else {
if ($this->_validSession) { if ($this->_validSession) {
Expand Down Expand Up @@ -277,8 +277,8 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
} }


return $this->_scaffoldForm($formAction); return $this->_scaffoldForm($formAction);
} elseif ($this->controller->_scaffoldError($action) === false) { } elseif ($this->controller->scaffoldError($action) === false) {
return $this->_scaffoldError(); return $this->scaffoldError();
} }
} }


Expand All @@ -290,7 +290,7 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
* @throws MethodNotAllowedException, NotFoundException * @throws MethodNotAllowedException, NotFoundException
*/ */
protected function _scaffoldDelete(CakeRequest $request) { protected function _scaffoldDelete(CakeRequest $request) {
if ($this->controller->_beforeScaffold('delete')) { if ($this->controller->beforeScaffold('delete')) {
if (!$request->is('post')) { if (!$request->is('post')) {
throw new MethodNotAllowedException(); throw new MethodNotAllowedException();
} }
Expand All @@ -313,7 +313,7 @@ protected function _scaffoldDelete(CakeRequest $request) {
); );
return $this->_sendMessage($message); return $this->_sendMessage($message);
} }
} elseif ($this->controller->_scaffoldError('delete') === false) { } elseif ($this->controller->scaffoldError('delete') === false) {
return $this->_scaffoldError(); return $this->_scaffoldError();
} }
} }
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Test/Case/Controller/ControllerTest.php
Expand Up @@ -666,10 +666,10 @@ public function testToBeInheritedGuardmethods() {
$request = new CakeRequest('controller_posts/index'); $request = new CakeRequest('controller_posts/index');


$Controller = new Controller($request, $this->getMock('CakeResponse')); $Controller = new Controller($request, $this->getMock('CakeResponse'));
$this->assertTrue($Controller->_beforeScaffold('')); $this->assertTrue($Controller->beforeScaffold(''));
$this->assertTrue($Controller->_afterScaffoldSave('')); $this->assertTrue($Controller->afterScaffoldSave(''));
$this->assertTrue($Controller->_afterScaffoldSaveError('')); $this->assertTrue($Controller->afterScaffoldSaveError(''));
$this->assertFalse($Controller->_scaffoldError('')); $this->assertFalse($Controller->scaffoldError(''));
} }


/** /**
Expand Down

0 comments on commit dbb87a0

Please sign in to comment.