public function createTeam() { if (isset($this->CURRENT_USER) and !$this->league->isManager($this->CURRENT_USER)) { $this->flashMessage('You don\'t have permission to view that page.', array('alertType' => 'error')); return $this->redirect('Leagues::index'); } if (!$this->league) { $redirectUrl = $this->request->env('HTTP_REFERER') ?: '/'; $this->flashMessage('League not found.', array('alertType' => 'error')); return $this->redirect($redirectUrl); } if ($this->league->isOver() or $this->league->isStarted()) { $this->flashMessage('Teams cannot be added to leagues that have already started.', array('alertType' => 'error')); return $this->redirect(array('Leagues::view', 'id' => $this->league->id)); } $team = Teams::create(); $team->league_id = $this->league->_id; if ($this->request->data and $team->save($this->request->data)) { $this->flashMessage('Team created successfully.', array('alertType' => 'success')); return $this->redirect(array('Leagues::view', 'id' => $this->league->_id)); } $limit_fields = false; return compact('team', 'limit_fields'); }