/** * 記事の追加 * * @param string $id * @throws NotFoundException */ private function __add($id = null) { if (!$id) { throw new NotFoundException(__('不正なアクセス')); } // セレクトボックスを持つため $this->loadModel('Topic'); // セレクトボックスは配列で1:値、2:画面表示で配列を持つ $this->set('seletopics', $this->Topic->find('list', array('fields' => array('id', 'topicname')))); // Topic_idへ記事を作成するトピックIDを選択 $this->set('topic_id', $id); if ($this->request->is('post')) { // debug($this->request->data); // throw new NotFoundException(); $this->Post->create(); // throw Exceptino; // ポストのユーザIDへログイン中のユーザIDを持たせる $this->request->data['Post']['user_id'] = $this->Auth->user('id'); // POSTされたデータは$this->request->dataに入ってる try { if ($this->Post->createWithAttachments($this->request->data)) { //debug($this->Post->getLastInsertID()); // 通知処理 $RM = new ReadManagementsController(); $RM->createWithTeacherRM($this->Post->getLastInsertID(), 'Post', $this->Auth->user('id')); $this->Session->setFlash(__('投稿が保存されました。')); return $this->redirect(array('action' => 'lists', $id)); } $this->Session->setFlash(__('投稿を追加できません。')); } catch (Exception $e) { $this->Session->setFlash($e->getMessage()); } } }