2012-09-24 54 views
0

即时通讯创建一个页面,当用户添加一条消息到数据库他们被带回到他们的查看消息页面(显示页面上的相关消息列表)。然而,当我点击提交添加消息时,它也不会将参数也传递给URL。cakephp传递参数后形式

public function add_admin($id=null){ 
    //allows user to add a new message to a dispute 
    $this->set('title_for_layout', 'Dispute Information'); 
    $this->set('stylesheet_used', 'homestyle'); 
    $this->set('image_used', 'eBOXLogoHome.png'); 
    $this->layout='home_layout'; 
    //gets messages where Message.dispute_id=$id 
    $dispute=$this->Message->field('dispute_id', array('dispute_id'=>$id)); 
    //sets the variables 

    $this->set('dispute', $dispute); 
    //$sets the variable $user to User.id 
    $user=$this->Auth->User('id'); 
    //sets the variable 
    $this->set('user',$user); 
    //if the request posts to the database 
    if($this->request->is('post')){ 
    //create an instance of message in the database 
     $this->Message->create(); 
    //if the message saves 
    if ($this->Message->save($this->request->data)) { 
    //redirect the user to Messages/viewMessage_admin 
     $this->redirect(array('controller' => 'Messages','action' => 'viewMessage_admin',$id)); 

    } 
    } 

    $this->set('id',$id); 

    } 

public function viewMessage_admin($id=null){ 
//allows users to view all messages related to a dispute 
$this->set('title_for_layout', 'Dispute Information'); 
$this->set('stylesheet_used', 'homestyle'); 
$this->set('image_used', 'eBOXLogoHome.png'); 
$this->layout='home_layout'; 
$this->set('dispute_id',$id); 
debug($id); 
//find all messages where Message.dispute_id=$id 
$Messages=$this->Message->find('all',array(
'conditions'=>array('dispute_id'=>$id))); 
//find User details where user.id=message.user_id 
$Username=$this->User->find('all', array(
'conditions'=>array(
'User.id'=>'Message.user_id'))); 
//get messages where message.dispute_id=$id 
$dispute=$this->Message->field('dispute_id', array('dispute_id'=>$id)); 
//sets the variables 
$this->set('dispute', $dispute); 
$this->set('username', $Username); 
$this->set('dispute_id',$id); 
$this->set('message',$Messages); 

} 

这里是我的形式

<table id="data"> 
<tr> 
<th>Please add your message below.</th></tr> 
<tr><td> 
<?php echo $this->Form->create('Message', array('action'=>'add_admin')); ?> 
<?php echo $this->Form->inpute('user_id', array('type'=>'hidden', 'value'=>$user)); ?> 
<?php echo $this->Form->input('message',array('label'=>false)); ?> 
</td></tr><tr><td> 
<?php echo $this->Form->hidden('dispute_id', array('value' => $dispute)); ?> 
<?php echo $this->Form->end('Submit'); ?></td></tr> 
</table> 

回答

0
public function add_admin($id=null){ 
    //allows user to add a new message to a dispute 
    $this->set('title_for_layout', 'Dispute Information'); 
    $this->set('stylesheet_used', 'homestyle'); 
    $this->set('image_used', 'eBOXLogoHome.png'); 
    $this->layout='home_layout'; 
    //gets messages where Message.dispute_id=$id 
    $dispute=$this->Message->field('dispute_id', array('dispute_id'=>$id)); 
    //sets the variables 

    $this->set('dispute', $dispute); 
    //$sets the variable $user to User.id 
    $user=$this->Auth->User('id'); 
    //sets the variable 
    $this->set('user',$user); 
    //if the request posts to the database 
    if($this->request->is('post')){ 
    //create an instance of message in the database 
     $this->Message->create(); 
    //if the message saves 
    if ($this->Message->save($this->request->data)) { 

    //redirect the user to Message.viewMessage_admin 
    $id = $this->data['Message']['dispute_id']; 
    $this->set('id',$id); 
    $this->redirect(array('controller'=>'Messages','action'=>'viewMessage_admin',$id)); 


    } 
    } 

    $this->set('id',$id); 

    } 
0

你不是应该这样做的代码?

if ($this->Message->save($this->request->data)) { 
    $this->redirect(array('controller' => 'Messages','action' => 'viewMessage_admin', $this->Message->id)); 

} 

它好像要重定向到保存的信息,所以请尝试使用$this->Message->id代替。

UPDATE

<?php echo $this->Form->create('Message', array('url'=>'/messages/add_admin/' . $id)); ?> 
+0

,抓住了message.id,我以后什么message.dispute_id作为参数 – user1393064