I have two tables in the DB, cards and comments. I have my CakePHP app up and running. When on cards view.ctp .. the related comments appear at bottom of page.
I want to click add new comment but add it specifically for current card eg pre-populate card field to show current category.
This is my current view new comment link:
<?php
echo $this->Html->link(__('New comment'), array('controller' => 'comments','action' => 'add'));
?>
This is my add comment controller:
public function add() {
if ($this->request->is('post')) {
$this->Comment->create();
if ($this->Comment->save($this->request->data)) {
$this->Session->setFlash(__('The comment has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The comment could not be saved. Please, try again.'));
}
}
$cards = $this->Comment->Card->find('list');
$this->set(compact('cards'));
}
How do I get the card to be set to current card for newly added comment?
I also want to be able to add new comment but with card blank.. ready for user to select if from list.