我是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 –