Thursday, March 7, 2013

Re: Redirecting to a different controller view in Cakephp

Hi,

i solve the problem with following

$this->redirect(array('controller' => 'posts', 'action'=>'view',$this->Post->id));



Am Donnerstag, 7. März 2013 11:32:47 UTC+1 schrieb Victor Musvibe:
I have to 2 models that are related ItQuery and ItQueryComment. When a user adds a ItQuery other users should be able to comment on it. What i am trying to achieve is when other users add comments on a query they should be redirect to the view of the query not the index page for the it_query_comments

here is my code for my comments add view

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

and here is my add function in the controller

    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'));
    }
   
If anyone could show me how to do this, that would be awesome. Thanks in advance

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: