1

こんにちはすべて私は2つのボタンがあるページを持っています。1つはユーザーが追加ページに移動してデータベースに追加し続けることを許可する必要があります。そうでない場合、他のボタンをクリックするとインデックスページに移動します。

現在、どちらも入力した情報をデータベースに追加してページを更新するだけなので、type_2ボタンをクリックしても、インデックスページには移動しません。

これがコントローラーのifステートメントです

if ($this->Field->save($this->request->data)) 
{ 
    if($this->params['form']['type_1'] == 'type_1') 
        { 
            $this->Session->setFlash('The field has been saved');  
            $this->redirect( array('controller' => 'Fields','action' => 'add'));
        } 
        else if($this->params['form']['type_2'] == 'type_2') 
        { 
            $this->Session->setFlash('The template has been saved'); 
            $this->redirect( array('controller' => 'Templates','action' => 'index'));
        } 


}

これがビューです

<?php

echo $this->Form->create('Field', array('action'=>'add'));


    echo $this->Form->create('Field', array('action'=>'add'));
    echo $this->Form->input('name', array('label'=>'Name: '));
    echo $this->Form->input('description', array('label'=>'Description: '));
    echo $this->Form->input('templates_id', array('label'=>'Template ID: ', 'type' => 'text'));//this would be the conventional fk fieldname
    echo $this->Form->button('Continue adding fields', array('name' => 'type', 'value' => 'type_1'));
    echo $this->Form->button('Finish adding fields', array('name' => 'type', 'value' => 'type_2'));
    echo $this->Form->end();


?>
4

2 に答える 2

0

条件が間違っている場合は、インデックス['form']['type_1']をチェックしています。['form']['type_2']これは['form']['type']両方の場合に行われる必要があり、次にそれらの値をチェックするため、次のようになります。

if ($this->Field->save($this->request->data)) 
{ 
    if($this->params['form']['type'] == 'type_1') 
        { 
            $this->Session->setFlash('The field has been saved');  
            $this->redirect( array('controller' => 'Fields','action' => 'add'));
        } 
        else if($this->params['form']['type'] == 'type_2') 
        { 
            $this->Session->setFlash('The template has been saved'); 
            $this->redirect( array('controller' => 'Templates','action' => 'index'));
        } 
}
于 2012-08-02T02:05:23.767 に答える
0

パラメータの代わりにリクエストを使用する必要がありました

if ($this->Field->save($this->request->data)) 
{  
    if($this->request->data['submit'] == "type_1") 
        { 
            $this->Session->setFlash('The field has been saved');  
            $this->redirect( array('controller' => 'fields','action' => 'add'));
        } 
        if($this->request->data['submit'] == "type_2") 
        { 
            $this->Session->setFlash('The template has been saved'); 
            $this->redirect( array('controller' => 'templates','action' => 'index'));
        } 


}
于 2012-08-02T02:24:56.967 に答える