我有一个页面,可以选择继续向模板添加字段或发布最终字段,然后转到索引页面。当用户创建模板时,他们会创建一个字段。被template.id
放入field.template_id
但当用户选择添加另一个字段时,我输了field.template_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
并重新加载页面时,它没有抓取template_id
并将其插入field.template_id