首先,对不起,如果这听起来太简单了。顺便说一句,我是 cakePHP 的新手。
我的目标是扩展通过它链接的team_id
in控制器season
standings
表
我目前的示范规则是:
- 每个赛季都有很多排名
- 每个排名代表一个团队。
- 基本上是赛季和球队=排名之间的多对多关系。
这是我的季节控制器:
class SeasonsController extends AppController
{
public $helpers = array('Html', 'Form');
public function view($id)
{
$this->Season->id = $id;
$this->set('season', $this->Season->read());
}
}
当我浏览单个季节 thru/cakephp/seasons/view/1
时,$season
数组显示:
Array
(
[Season] => Array
(
[id] => 1
[name] => English Premier League 2013/2014
[start] => 1350379014
[end] => 0
)
[Standing] => Array
(
[0] => Array
(
[id] => 1
[team_id] => 1
[win] => 1
[lose] => 0
[draw] => 1
[GF] => 5
[GA] => 4
[season_id] => 1
[rank] => 1
)
[1] => Array
(
[id] => 2
[team_id] => 2
[win] => 0
[lose] => 1
[draw] => 1
[GF] => 4
[GA] => 5
[season_id] => 1
[rank] => 2
)
)
)
结果只显示team_id
,但我怎样才能得到进一步的扩展team_id
呢?
我已经在我的团队模型中添加了以下内容,但仍然没有自动链接。以下是我的所有模型:
class Team extends AppModel
{
public $name = 'Team';
public $hasMany = array(
'Standing' => array(
'className' => 'Standing'
));
}
class Season extends AppModel
{
public $name = 'Season';
public $hasMany = array(
'Standing' => array(
'className' => 'Standing'
));
}
class Standing extends AppModel
{
public $name = 'Standing';
public $belongsTo = array(
'Team' => array(
'className' => 'Team',
'foreignKey' => 'team_id',
),
'Season' => array(
'className' => 'Season',
'foreignKey' => 'season_id',
),
);
}