Skip to content

Instantly share code, notes, and snippets.

@zaininnari
Created June 22, 2010 13:03
Show Gist options
  • Save zaininnari/448439 to your computer and use it in GitHub Desktop.
Save zaininnari/448439 to your computer and use it in GitHub Desktop.
<?php
// ProjectsController
function add() {
if (!empty($this->data)) {
$this->Project->create();
$this->Project->begin();
$this->Project->setInitData($this->data);
$isProject = $this->Project->save($this->data);
$projectId = $this->Project->getInsertID();
$this->Project->State->setInitDataState($this->data, array('project_id' => $projectId));
$isState = $this->Project->State->saveAll($this->data['State'], array('validate' => false, 'atomic' => false));
if ($isProject && $isState && $this->Project->commit()) {
$this->Session->setFlash(__('The Project has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Project->rollback();
$this->Session->setFlash(__('The Project could not be saved. Please, try again.', true));
}
}
$users = $this->Project->User->find('list');
$this->set(compact('users'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment