1

私はこれに対する答えを見つけるのに苦労しています。私は CakePHP を 1 か月しか使用していませんが、問題が発生しました。値を手動で挿入することで修正できるものですが、データが事前に入力されることを期待していました。何が起こっているかは次のとおりです。

モデルは多くの「動的価格」を持つ製品です

ID 7 (/products/edit/7) の製品をテストしています。

私の編集機能の最初の部分は次のとおりです。

public function edit($id = null) {
    $this->Product->id = $id;

    if (!$this->Product->exists()) {
        throw new NotFoundException('Invalid Product');
    }

    if ($this->request->is('get')){
        $this->request->data = $this->Product->read();
    }
    debug($this->request->data); 
    //other stuff setting vars for drop-down lists
}

debug($this->request->data); 

私に次を与えます:

array(
'Product' => array(
'id' => '7',
'category_id' => '70',
'name' => 'Full Test',
'description' => 'This is to test all features',
'price' => '0.00',
'aesthetic' => true,
'image' => '',
'price_structure' => '2',
'suggest_for' => '',
'created' => '2012-06-28 12:49:06',
'modified' => '2012-06-28 12:49:06'
),
'Dynamicprice' => array(
  (int) 0 => array(
  'id' => '15',
  'product_id' => '7',
  'drop' => '600',
  'prices' => '6000:9.99, 12000:18.99 '
  ),
  (int) 1 => array(
  'id' => '16',
  'product_id' => '7',
  'drop' => '1200',
  'prices' => '6000:19.99, 12000:28.99 '
  ),
  (int) 2 => array(
  'id' => '17',
  'product_id' => '7',
  'drop' => '2400',
  'prices' => '6000:29.99, 12000:38.99 '
  )
)
)

ただし、['Product'] のすべてが ['Dynamicprice'] 配列に事前入力されますが、以下は事前入力されません。

<?php
echo $this->Form->input('Dynamicprices.0.id');
echo $this->Form->input('Dynamicprices.0.drop', array('label' => 'Drop 1 (mm). Enter "0" for "Any Drop"'));
echo $this->Form->input('Dynamicprices.0.prices', array('label' => 'Prices 1', 'type' => 'textarea', 'rel' => 'dynamic'));
?><hr><?php
echo $this->Form->input('Dynamicprices.1.id');
echo $this->Form->input('Dynamicprices.1.drop', array('label' => 'Drop 2 (mm).'));
echo $this->Form->input('Dynamicprices.1.prices', array('label' => 'Prices 2', 'type' => 'textarea', 'rel' => 'dynamic'));
?><hr><?php
echo $this->Form->input('Dynamicprices.1.id');
echo $this->Form->input('Dynamicprices.2.drop', array('label' => 'Drop 3 (mm).'));
echo $this->Form->input('Dynamicprices.2.prices', array('label' => 'Prices 3', 'type' => 'textarea', 'rel' => 'dynamic'));
?>

それらが自動的に入力されると期待するのは正しいですか?もしそうなら、私は何を間違えましたか?

/Model/Dynamicprice.php を次のように作成して確認しました。

   class Dynamicprice extends AppModel {
    public $name = 'Dynamicprice';
    public $belongsTo = 'Product';

でも思った通り何も変わらなかった。

4

1 に答える 1

1

今週これを行うのは 2 回目です。愚かな質問をします。はい、それらが事前に入力されることを期待するのは正しかったです。問題は、命名規則が混同されていることです。"Dynamicprices.1.drop" の末尾に「s」を付けないでください。愚かな私!

于 2012-06-29T11:24:16.133 に答える