模板只能访问 "foreign" table 的 ID

Template only has access to ID's of "foreign" table

我一直在关注 cakephp 网站上的 example 并为我的项目修改它 "works"。

我有一个 table,其中一列是另一个 table 的外键,但我的模板只填充了 ID 而不是(外)table。如何在我的模板视图中访问 "categorieen.type"?

+----------------------------------+
|           PRODUCTEN              | 
+----------------------------------+
| productenid  (PK)                | 
| categorie    (FK)                | 
+----------------------------------+

+----------------------------------+
|           CATEGORIEEN            |
+----------------------------------+
| categorieid  (PK)                | 
| type                             | 
+----------------------------------+

ProductenTable

class ProductenTable extends Table {

    public function initialize(array $config){
        $this->belongsTo('Categorieen');
        $this->addBehavior('Timestamp');
    }
    ...
}

ProductenController

public function add() {
        $product = $this->Producten->newEntity();
        if ($this->request->is('post')) {
            $product = $this->Producten->patchEntity($product, $this->request->getData());

            if ($this->Producten->save($product)) {
                $this->Flash->success(__('Your product has been saved.'));
                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('Unable to add your product.'));
        }

        $categorieen = $this->Producten->Categorieen->find('list');

        $this->set('product', $product);
        $this->set('categorieen', $categorieen);
    }

add.ctp

echo $this->Form->control('categorieen', ['options' => $categorieen]);

我不得不将我的 add() 更改为:

public function add() {
        $product = $this->Producten->newEntity();
        if ($this->request->is('post')) {
            $product = $this->Producten->patchEntity($product, $this->request->getData());

            if ($this->Producten->save($product)) {
                $this->Flash->success(__('Your product has been saved.'));
                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('Unable to add your product.'));
        }

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

        $this->set('product', $product);
        $this->set('categorieen', $categorieen);
    }

和我的edit.ctp到:

echo $this->Form->control('categorie', ['options' => $categorieen]);