需要更多信息来调试数据更新

时间:2019-01-04 20:39:09

标签: debugging pivot-table cakephp-3.0

我在通过数据透视表编辑对象时遇到了一些麻烦,并且很难调试问题。每次按下“保存”按钮时,都会出现“无法更新您的产品”错误,但没有上下文。

我确实查看了CakePHP调试工具包中的SQL日志,但仅找到SELECT且没有UPDATE语句。我感觉数据已经被覆盖。

是否有更好的方法可以在控制器中调试此类问题?

public function edit($slug) {
    $product = $this->Producten
        ->findBySlug($slug)
        ->contain(['Categorieen', 'Winkels'])
        ->firstOrFail();

    if ($this->request->is(['post', 'put'])) {
        $this->Producten->patchEntity($product, $this->request->getData());
        if ($this->Producten->save($product)) {
            $this->Flash->success(__('Your product has been updated.'));
            return $this->redirect(['action' => 'index']);
        }
        debug($product);       --> dump below
        $this->Flash->error(__('Unable to update your product.'));
    }
    $this->set('product', $product);

    $categorieen = $this->Producten->Categorieen->find('list', [
        'keyField' => 'categorieid', 
        'valueField' => 'type'
    ]);     
    $this->set('categorieen', $categorieen);

    $winkels = $this->Producten->Winkels->find('list', [
        'keyField' => 'winkel_id', 
        'valueField' => 'naam'
    ]);    
    $this->set('winkels', $winkels);

}

调试转储

object(Cake\ORM\Entity) {

    'idproducten' => (int) 1,
    'merk' => 'Xiaomi',
    'model' => 'Mi Electric',
    'topsnelheid' => (int) 25,
    'bereik' => (int) 30,
    'gewicht' => (float) 12.2,
    'max_belasting' => (float) 99,
    'uitneembare_batterij' => false,
    'beschrijving' => 'stuff...',
    'categorie_id' => (int) 1,
    'thumbnail' => '',
    'afbeelding' => '',
    'tech_spec_url' => '',
    'slug' => 'xiaomi-mi-electric',
    'aangemaakt' => object(Cake\I18n\FrozenTime) {

        'time' => '2018-12-20T22:03:49+00:00',
        'timezone' => 'UTC',
        'fixedNowTime' => false

    },
    'aangepast' => object(Cake\I18n\FrozenTime) {

        'time' => '2018-12-20T22:04:24+00:00',
        'timezone' => 'UTC',
        'fixedNowTime' => false

    },
    'winkels' => [
        (int) 0 => object(App\Model\Entity\Winkel) {

            '_joinData' => object(Cake\ORM\Entity) {

                'winkel_id' => (int) 1,
                'url' => 'test',
                'prijs' => (float) 0.99,
                '[new]' => true,
                '[accessible]' => [
                    '*' => true
                ],
                '[dirty]' => [
                    'winkel_id' => true,
                    'url' => true,
                    'prijs' => true
                ],
                '[original]' => [],
                '[virtual]' => [],
                '[errors]' => [],
                '[invalid]' => [],
                '[repository]' => 'ProductenWinkels'

            },
            '[new]' => true,
            '[accessible]' => [
                'naam' => true,
                'winkel_url' => true,
                'logo' => true
            ],
            '[dirty]' => [
                '_joinData' => true
            ],
            '[original]' => [],
            '[virtual]' => [],
            '[errors]' => [
                'logo' => [
                    '_required' => 'This field is required'
                ]
            ],
            '[invalid]' => [],
            '[repository]' => 'Winkels'

        }
    ],
    'categorieen' => object(Cake\ORM\Entity) {

        'categorieid' => (int) 1,
        'type' => 'step',
        '[new]' => false,
        '[accessible]' => [
            '*' => true
        ],
        '[dirty]' => [],
        '[original]' => [],
        '[virtual]' => [],
        '[errors]' => [],
        '[invalid]' => [],
        '[repository]' => 'Categorieen'

    },
    '[new]' => false,
    '[accessible]' => [
        '*' => true
    ],
    '[dirty]' => [
        'winkels' => true
    ],
    '[original]' => [
        'winkels' => []
    ],
    '[virtual]' => [],
    '[errors]' => [],
    '[invalid]' => [],
    '[repository]' => 'Producten'

1 个答案:

答案 0 :(得分:0)

debug()转储中的错误键说明了一切。