Created
June 30, 2017 04:08
-
-
Save cpierce/11e60c9e7bb1e8f3baa20832ca7032c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add Method. | |
* | |
* @return \Cake\Controller\Controller::redirect | |
*/ | |
public function add() | |
{ | |
$table = TableRegistry::get($this->modelClass); | |
$data = $table->newEntity(); | |
$name = Inflector::singularize($this->modelClass); | |
if ($this->request->is(['post', 'put'])) { | |
$data = $table->patchEntity($data, $this->request->data); | |
if ($table->save($data)) { | |
$this->Flash->success(__('The ' . $name . ' has been added.')); | |
return $this->redirect([ | |
'action' => 'index', | |
]); | |
} | |
$this->Flash->error(__('Unable to add the ' . $name . '.')); | |
} | |
$template = Configure::read('templates.default'); | |
$this->set(compact('data', 'template')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment