重定向到Cakephp中的不同控制器视图

时间:2013-03-07 10:14:41

标签: cakephp

我需要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'));
}

如果有人能告诉我如何做到这一点,那将是非常棒的。提前致谢

1 个答案:

答案 0 :(得分:3)

尝试以下

$this->redirect(array(
    'controller' => 'it_queries',
    'action' => 'view', 
    $this->request->data['ItQuery']['id'])
);
相关问题