Database cakephp数据库未保存正确的信息
my函数将正确的值放入窗体以供查看,但不会将正确的值保存到数据库中。数据库正在保存Database cakephp数据库未保存正确的信息,database,forms,cakephp,Database,Forms,Cakephp,my函数将正确的值放入窗体以供查看,但不会将正确的值保存到数据库中。数据库正在保存帐户\u用户。id而不是帐户\u用户。帐户\u id到我的帐户。代码看起来应该输入人员帐户\u用户。帐户\u id。我在表单的下拉框中看到了正确的信息 添加函数 function add(){ $accounts=$this->User->AccountsUser->find('list', array( 'fields'=>array('id','account_id'),'co
帐户\u用户。id
而不是帐户\u用户。帐户\u id
到我的帐户。代码看起来应该输入人员帐户\u用户。帐户\u id
。我在表单的下拉框中看到了正确的信息
添加函数
function add(){
$accounts=$this->User->AccountsUser->find('list', array(
'fields'=>array('id','account_id'),'conditions' => array(
'user_id' => $this->Auth->user('id'))));
if($this->request->is('post')){
$this->Template->create();
if ($this->Template->save($this->request->data)) {
$this->Session->setFlash('The template has been saved');
$this->redirect( array('controller' => 'Fields','action' => 'add'));
} else {
$this->Session->setFlash('The template could not be saved. Please, try again.');
}
}
这是添加视图
<?php
echo $this->Form->create('Template', array('action'=>'add'));
echo $this->Form->input('name',array('label'=>'Template Name: '));
echo $this->Form->input('account_id',array('label'=>'Business: ', 'type' => 'select', 'options' => $accounts));
echo $this->Form->input('description',array('label'=>'Short Description Of Template: '));
echo $this->Form->end('Click Here To Submit Template');
?>
请尝试以下代码:
function add(){
$accounts=$this->User->AccountsUser->find('list', array(
'fields'=>array('account_id','account_id'),'conditions' => array(
'user_id' => $this->Auth->user('id'))));
if($this->request->is('post')){
$this->Template->create();
if ($this->Template->save($this->request->data)) {
$this->Session->setFlash('The template has been saved');
$this->redirect( array('controller' => 'Fields','action' => 'add'));
} else {
$this->Session->setFlash('The template could not be saved. Please, try again.');
}
}
请尝试以下代码:
function add(){
$accounts=$this->User->AccountsUser->find('list', array(
'fields'=>array('account_id','account_id'),'conditions' => array(
'user_id' => $this->Auth->user('id'))));
if($this->request->is('post')){
$this->Template->create();
if ($this->Template->save($this->request->data)) {
$this->Session->setFlash('The template has been saved');
$this->redirect( array('controller' => 'Fields','action' => 'add'));
} else {
$this->Session->setFlash('The template could not be saved. Please, try again.');
}
}
我更改了查询中的
字段
选项。请检查并询问它是否对您有效。我在您的查询中更改了字段
选项。请检查并询问它是否对您有效。