我是CakePHP的新手,需要一些幫助。我烘烤了我的第一個應用程序,但我無法使其表現得如我所願。蛋糕PHP選擇下拉菜單
我有兩個表格,球員和球隊,以及一個聯盟表players_teams。表單顯示正常。但我想將選擇區域更改爲下拉菜單。隨着時間的推移,玩家可能會有很多團隊(我爲此添加了一個來自和來自日期列的連接表),但我希望玩家在創建時被分配給一個團隊。
這是我曾嘗試:
<?php
echo $this->Form->input('player_name');
echo $this->Form->input('player_last_name');
echo $this->Form->input('player_number');
echo $this->Form->input('player_birthday');
echo $this->Form->input('teams._ids', [ 'multiple' => false, 'options' => $teams,]);
?>
它不更改爲dropdow。我也試過這樣:
echo $this->Form->input('teams._ids', ['type' => 'select', 'multiple' => false, 'options' => $teams, 'empty' => true]);
這最後一個改變選擇的下拉列表中,但無論我選擇不進入數據庫。
繼承人供玩家控制器:
public function add()
{
$player = $this->Players->newEntity();
if ($this->request->is('post')) {
$player = $this->Players->patchEntity($player, $this->request->data);
if ($this->Players->save($player)) {
$this->Flash->success(__('The player has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The player could not be saved. Please, try again.'));
}
}
$teams = $this->Players->Teams->find('list', ['limit' => 200]);
$this->set(compact('player', 'teams'));
$this->set('_serialize', ['player']);
}
這裏的PlayersTeamController:
public function add()
{
$playersTeam = $this->PlayersTeams->newEntity();
if ($this->request->is('post')) {
$playersTeam = $this->PlayersTeams->patchEntity($playersTeam, $this->request->data);
if ($this->PlayersTeams->save($playersTeam)) {
$this->Flash->success(__('The players team has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The players team could not be saved. Please, try again.'));
}
}
$players = $this->PlayersTeams->Players->find('list', ['limit' => 200]);
$teams = $this->PlayersTeams->Teams->find('list', ['limit' => 200]);
$this->set(compact('playersTeam', 'players', 'teams'));
$this->set('_serialize', ['playersTeam']);
}
任何幫助將非常感激。謝謝!
我得到這個:錯誤:不能使用Cake \ ORM \ Query類型的對象作爲數組 –
@MiguelCedenoAgamez我實際上對CakePHP沒有任何瞭解;我只是一個快速的Google員工。對不起 – Terminus
不好運! @Terminus –