大家好,我有一个有两个按钮的页面,一个应该允许该人进入添加页面并继续添加到数据库,否则如果他们单击另一个按钮,它将进入索引页面。
目前他们都只是将输入的信息添加到数据库中并刷新页面,所以当一个人点击 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();
?>