Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function add() {
- $post = $this->Posts->newEntity($this->request->data, ['associated' => ['Categories' => ['validate' => 'notEmpty']]]);
- if ($this->request->is('post')) {
- $newData = ['user_id' => $this->Auth->user('id')];
- // $this->request->data['user_id'] = $this->Auth->user('id');
- $post = $this->Posts->patchEntity($post, $newData);
- // $post->user_id = $this->Auth->user('id');
- // debug($post);exit;
- if ($this->Posts->save($post)) {
- $this->Flash->success(__('Your post has been saved.'));
- return $this->redirect(['action' => 'index']);
- }
- $this->Flash->error(__('Unable to save your post.'));
- }
- $categories = $this->Posts->Categories->find('list');
- $this->set('post', $post);
- $this->set(compact('post', 'categories'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement