データベースにデータを追加するフォームを作成しようとしています。私のテーブルは、クーポンと呼ばれ、私は次のコードを持っている:エラー:SQLSTATE [42000]:構文エラーまたはアクセス違反:1066ユニークではないテーブル/エイリアス: 'Coupons'
//CouponsController.php
public function addCoupon() {
$coupon = $this->Coupons->newEntity();
if ($this->request->is('post')) {
$coupon = $this->Coupons->patchEntity($coupon, $this->request->data);
if ($this->Coupons->save($coupon)) {
$this->Flash->success(__('The coupon has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The coupon could not be saved. Please, try again.'));
}
}
$coupons = $this->Coupons->Coupons->find('list', ['limit' => 200]);
$this->set(compact('coupon', 'coupons'));
$this->set('_serialize', ['coupon']);
}
//CouponsTable.php
public function initialize(array $config)
{
parent::initialize($config);
$this->table('coupons');
$this->displayField('coupon_id');
$this->primaryKey('coupon_id');
$this->belongsTo('Coupons', [
'foreignKey' => 'coupon_id',
'joinType' => 'INNER'
]);
}
//add_coupon.ctp
<h3>Add Coupon</h3>
<?php
echo $this->Form->create(null,['url' => ['action' => 'addCoupon']]);
echo $this->Form->input('coupon_code');
echo $this->Form->input('expiration_date');
echo $this->Form->input('discount_amount');
echo $this->Form->input('usage_limit');
echo $this->Form->input('domain_limit');
echo $this->Form->input('description');
echo $this->Form->input('type');
echo $this->Form->button('Submit');
echo $this->Form->end();
?>
提出に私をクリックすると、データはデータベースに格納されますが、私は「エラーを提示しています:SQLSTATE [42000]:構文エラーまたはアクセス違反:1066ユニークではないテーブル/エイリアス: 'Coupons' "。 SQLクエリ:Coupons__coupon_id
AS SELECT Coupons.coupon_id、Coupons__coupon_code
AS Coupons.coupon_code、Coupons__expiration_date
AS Coupons.expiration_date、Coupons__discount_amount
AS Coupons.discount_amount、Coupons__usage_limit
AS Coupons.usage_limit、Coupons__domain_limit
AS Coupons.domain_limit、Coupons__description
AS Coupons.description、クーポン。タイプAS Coupons__type
クーポンからクーポンINNER JOINクーポンクーポンON Coupons.coupon_id =(Coupons.coupon_id)LIMIT 20 OFFSET 0 ここで問題は何ですか?
$this->Coupons->find('list', ['limit' => 200])
へ
私は試しても動作しませんでした。 – user2817869