Skip to content

Instantly share code, notes, and snippets.

@robwilkerson
Created February 6, 2012 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwilkerson/1753441 to your computer and use it in GitHub Desktop.
Save robwilkerson/1753441 to your computer and use it in GitHub Desktop.
CakePHP edit method example.
/**
* Allows an administrator to create a new user.
*
* @param uuid id A user id.
* @access public
*/
public function admin_edit( $id ) {
$this->User->id = $id;
if( !empty( $this->data ) ) {
if( $this->User->save( $this->data ) ) {
$this->Session->setFlash( sprintf( __( 'User details were updated successfully.', true ), h( $this->data['User']['first_name'] ) ), null, null, 'success' );
$this->redirect( array( 'action' => 'index', 'admin' => true ) );
}
else {
$this->Session->setFlash( __( 'There was a problem updating this user\'s details. Please check below for any error details.', true ), null, null, 'validation' );
}
}
else {
$this->data = $this->User->read();
}
}
/**
* Allows an administrator to create a new user.
*
* @param uuid id A user id.
* @access public
*/
public function admin_edit( $id ) {
$this->User->id = $id;
if( !empty( $this->data ) ) {
if( $this->User->save( $this->data ) ) {
$this->Session->setFlash( sprintf( __( 'User details were updated successfully.', true ), h( $this->data['User']['first_name'] ) ), null, null, 'success' );
$this->redirect( array( 'action' => 'index', 'admin' => true ) );
}
else {
$this->Session->setFlash( __( 'There was a problem updating this user\'s details. Please check below for any error details.', true ), null, null, 'validation' );
}
}
else {
$this->data = $this->User->read();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment