0

ItQueryとItQueryCommentに関連する2つのモデルが必要です。ユーザーがItQueryを追加すると、他のユーザーがそれにコメントできるようになります。私が達成しようとしているのは、他のユーザーがクエリにコメントを追加するときに、it_query_commentsのインデックスページではなく、クエリのビューにリダイレクトする必要があることです。

これが私のコメントの追加ビューのコードです

<?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'));
}

誰かが私にこれを行う方法を教えてくれるなら、それは素晴らしいでしょう。前もって感謝します

4

1 に答える 1

3

次を試してください

$this->redirect(array(
    'controller' => 'it_queries',
    'action' => 'view', 
    $this->request->data['ItQuery']['id'])
);
于 2013-03-07T10:37:28.243 に答える