0

我必须有 2 个与 ItQuery 和 ItQueryComment 相关的模型。当用户添加 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 回答