0
我必須使用2個與ItQuery和ItQueryComment相關的模型。當用戶添加一個ItQuery時,其他用戶應該能夠對其進行評論。我試圖做到的,是當其他用戶在查詢中添加註釋,他們應該重定向到查詢沒有索引頁的it_query_comments重定向到Cakephp中的不同控制器視圖
這裏的觀點是我的代碼爲我的註釋添加視圖
<?php echo $this->Form->create('ItQueryComment'); ?>
<fieldset>
<legend><?php echo __('Add It Query Comment'); ?></legend>
<?php
echo $this->Form->input('it_query_id');
echo $this->Form->input('comment');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
,這裏是在控制器
public function add() {
if ($this->request->is('post')) {
$this->ItQueryComment->create();
if ($this->ItQueryComment->save($this->request->data)) {
$this->Session->setFlash(__('The it query comment has been saved'));
$this->redirect(array('controller' => 'it_queries','action' => 'view', $itQuery['ItQuery']['id']));
} else {
$this->Session->setFlash(__('The it query comment could not be saved. Please, try again.'));
}
}
$itQueries = $this->ItQueryComment->ItQuery->find('list');
$this->set(compact('itQueries'));
}
如果有人能告訴我怎麼做我的附加功能,這將是真棒。在此先感謝
它仍然沒有拉動ID。 – 2013-03-07 10:41:02
如果你遵循CakePHP約定,Query的放置註釋的'id'應該在你發佈的數據中的某處,它應該在這裏:'$ this-> request-> data ['ItQueryComment'] ['it_query_id ']'否則調試($ this-> request-> data);在'save()'之前,檢查存在的值。你必須在你的config.php中啓用調試才能看到這個 – thaJeztah 2013-03-07 10:45:54
@thaJeztah謝謝你的工作。 – 2013-03-07 10:48:55