Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. public function add() {
  2. $post = $this->Posts->newEntity($this->request->data, ['associated' => ['Categories' => ['validate' => 'notEmpty']]]);
  3.  
  4. if ($this->request->is('post')) {
  5. $newData = ['user_id' => $this->Auth->user('id')];
  6. // $this->request->data['user_id'] = $this->Auth->user('id');
  7. $post = $this->Posts->patchEntity($post, $newData);
  8. // $post->user_id = $this->Auth->user('id');
  9. // debug($post);exit;
  10. if ($this->Posts->save($post)) {
  11. $this->Flash->success(__('Your post has been saved.'));
  12. return $this->redirect(['action' => 'index']);
  13. }
  14.  
  15. $this->Flash->error(__('Unable to save your post.'));
  16. }
  17. $categories = $this->Posts->Categories->find('list');
  18. $this->set('post', $post);
  19. $this->set(compact('post', 'categories'));
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement