嗨,我有頁面有兩個按鈕,應該允許人去添加頁面,並繼續添加到數據庫,否則,如果他們點擊另一個按鈕,它會進入索引頁面。cakephp重定向按鈕
目前他們都只是將輸入的信息添加到數據庫並刷新頁面,因此當一個人點擊type_2按鈕時,他們不會被帶到索引頁面。
這裏是控制器
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'));
}
}
這裏的if語句
<?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();
?>
你是完全正確的,你人忽略使用'$這個 - > params',而不是'$這個 - >請求 - > data'。 – pbond 2012-08-02 22:41:54