2016-04-20 34 views
0

错误在于,在创建控制器代码时,关联模型的变量留空,并且该模型的名称留空。为我的所有表格创建控制器时发生错误,但这里是其中一个表格的完整示例。我已经在全新安装的cakephp 3.2上复制了这个问题。使用SQLite3烘焙CakePHP 3.2的控制器会在add()和edit()方法中产生错误,为什么代码生成不正确?

这里是2线中产生不正确的代码,我在下面列出的全部细节:在配置/ app.php

$ = $this->Customers->->find('list', ['limit' => 200]); 
    $this->set(compact('customer', '')); 

我的数据库配置:

'default' => [ 
    'className' => 'Cake\Database\Connection', 
    'driver' => 'Cake\Database\Driver\Sqlite', 
    'persistent' => false, 
    'host' => 'localhost', 
    //'port' => 'non_standard_port_number', 
    'username' => null, 
    'password' => null, 
    'database' => 'tgr.db', 
    'encoding' => 'utf8', 
    'timezone' => 'UTC', 
    'flags' => [], 
    'cacheMetadata' => true, 
    'log' => false, 
    'quoteIdentifiers' => false, 
    'url' => env('DATABASE_URL', null), 
] 

的代码创建对于包含不正确创建的代码的add()方法。

public function add(){ 
    $customer = $this->Customers->newEntity(); 
    if ($this->request->is('post')) { 
     $customer = $this->Customers->patchEntity($customer, $this->request->data); 
     if ($this->Customers->save($customer)) { 
      $this->Flash->success(__('The customer has been saved.')); 
      return $this->redirect(['action' => 'index']); 
     } else { 
      $this->Flash->error(__('The customer could not be saved. Please, try again.')); 
     } 
    } 
    $ = $this->Customers->->find('list', ['limit' => 200]); 
    $this->set(compact('customer', '')); 
    $this->set('_serialize', ['customer']); 
} 

我的数据库存储INT应用程序根目录和应用程序发现它和我可以告诉正确连接。数据库架构:

-- Text encoding used: UTF-8 
-- 
PRAGMA foreign_keys = off; 
BEGIN TRANSACTION; 

-- Table: customers 
CREATE TABLE customers (_id INTEGER PRIMARY KEY,district_key INTEGER NOT NULL, name TEXT UNIQUE NOT NULL, short_name TEXT UNIQUE NOT NULL, job_count INTEGER, report_count INTEGER, FOREIGN KEY (district_key) REFERENCES districts (_id) ); 

COMMIT TRANSACTION; 
PRAGMA foreign_keys = on; 

回答

0

我找到了答案。我的数据库id列是_id(来自android默认id列),cakephp面包店正在将这个相关模型与一个空名称相关联,它意味着它将采用_id之前的任何内容并为其创建一个模型。我更新了所有的数据库表来反映这一点,并且它工作正常。

相关问题