I am new to Cakephp and am working on the blog tutorial. Everything works fine except one part I can’t figure out. I just used a bake all for categories and articles pieces, but when you try to edit or add a new article, the drop down list is not populated with categories. It is just blank. How do I go about fixing this?
ArticlesController: (edit segment)
public function edit($id = null)
{
$article = $this->Articles->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$article = $this->Articles->patchEntity($article, $this->request->getData());
if ($this->Articles->save($article)) {
$this->Flash->success(__('The article has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The article could not be saved. Please, try again.'));
}
$this->set(compact('article'));
$this->set('_serialize', ['article']);
}
ArticlesTable: relevant part
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('articles');
$this->setDisplayField('title');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Categories', [
'foreignKey' => 'category_id',
]);
}