Session cakephp重新加载页面并传递参数

Session cakephp重新加载页面并传递参数,session,cakephp,reload,Session,Cakephp,Reload,我有一个页面,可以选择继续向模板添加字段,或者发布最终字段,然后转到索引页面。当用户创建模板时,会将其用于创建字段。template.id放在字段.template\u id中,但当用户选择添加另一个字段时,我将丢失字段.template\u id 这是我函数的代码 function add($last=null){ $this->set('title_for_layout', 'Create Fields'); $this->set('stylesheet_use

我有一个页面,可以选择继续向模板添加字段,或者发布最终字段,然后转到索引页面。当用户创建模板时,会将其用于创建字段。
template.id
放在
字段.template\u id
中,但当用户选择添加另一个字段时,我将丢失
字段.template\u id

这是我函数的代码

function add($last=null){

    $this->set('title_for_layout', 'Create Fields');
    $this->set('stylesheet_used', 'homestyle');
    $this->set('image_used', 'eBOXLogoHome.png');
    $this->layout='home_layout';

        //retrieve Account Id of current User       
        $accountid=$this->Auth->user('account_id');


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

    if($this->request->is('post'))
    {

    $this->Field->create(); 

    if ($this->Field->save($this->request->data))
    {   
        if($this->request->data['submit'] == "type_1") 
            {

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


    }
    else
    {
        $this->Session->setFlash('The field could not be saved. Please, try again.'); 
    } 
 }
     $this->set('accounts', $accounts); 
     $this->set('last', $last); 


  }

} 

我遇到的问题是,当用户单击
type_1
并重新加载页面时,它没有抓取
模板id
并将其插入
字段。模板id

根据您的代码,无论何时将表单发布到add()方法,您都会发现$last。将此字段移到
if($this->request->is('post'))
之外,即可找到条件

由于read方法会覆盖存储在模型的data和id属性中的任何信息,因此在一般情况下使用此函数时应该非常小心,尤其是在模型回调函数(如beforeValidate和beforeSave)中使用此函数。通常,find函数提供了比read方法更健壮、更易于使用的API


不清楚到底是什么错误?当我转到type1时,模板id在表单/URL中不可用。如果我这样做,在我最初创建template.id并重定向到此页面后,它不会获取template.id。另外,在手动将$last输入字段后,它不会将其保留在那里