Temat: Problem z przechwytywaniem danych
Mam problem z przechwytywaniem danych ![]()
Sytuacja wygląda następująco mam link który prowadzi do formularze z dodawaniem komentarza:
<?php echo $html->link('Dodaj Komentarz',
'/comments/add/'.$data['Post']['id']); ?>Oraz funkcje która służy do dodawania do bazy komentarza:
function add($post_id) {
if (!empty($this->data)) {
if ($this->Comment->save($this->data)) {
$this->flash('Your Comment has been saved.', '/posts');
}
}
}Czy aby funkcja add przechwyciła $data['Post']['id'],
wystarczy $this->Post->setPost_id($post_id), a jeżeli tak to w którym miejscu trzeba ją wstawić ?(kiedy wstawiam ją na początku funkcji nie działam, tak samo w warunku)
Czy trzeba to rozwiązać inaczej?
Tak aby pole Post_id w zapisywanym komentarzu miało wartość $data['Post']['id'] ??
Kod formularza dodającego komentarz:
<div class="comment form">
<form id="CommentAddForm" method="post" action="/cake/app/webroot/index.php/comments/add">
<fieldset style="display:none;"><input type="hidden" name="_method" value="POST" /></fieldset><fieldset><legend>New Comment</legend>
<input type="hidden" name="data[Comment][id]" value="" id="CommentId" /><div class="input select"><label for="CommentPostId">Post</label><input type="hidden" name="data[Comment][post_id]" value="" id="CommentPostId" /></div>
<div class="input text"><label for="CommentAuthor">Author</label>
<input name="data[Comment][author]" type="text" maxlength="50" value="" id="CommentAuthor" /></div>
<div class="input textarea"><label for="CommentBody">Body</label><textarea name="data[Comment][body]" cols="30" rows="6" id="CommentBody" ></textarea>
</div></fieldset><div class="submit"><input type="submit" value="Submit" /></div></form></div>