我在 cakephp 上开发一个应用插件。我被困在一个功能上,演示如下:
在数据库中,我有一个包含数据的表“平台”('1' => 'PC','2' => 'PS3' ...)。
在游戏视图中,我有:
<? $platformes = array($igra['Igra']['pid']); /* gives me 1,2 */ $platforme = $this->requestAction( array( 'plugin' => 'gamer', 'controller' => 'Igra', 'action' => 'getPlatformaIme' ), $platformes ); ?>
在控制器中,我有这样的功能:
function getPlatformaIme($pids) { $platforme = explode(', ', $pids); $this->loadModel('Gamer.Platforme'); foreach($platforme as $pid) { $this->Platforme->find('all', array( 'conditions' => array('Platforme.id' => $pid) )); $name[] = $this->Platforme->field('name'); } return implode(', ', $name); }
这应该给我PC,PS3,但它没有。它给了我 PC,即使数组中没有 1。我怎样才能修复我的功能工作?
Tnx 的帮助,这是正确的方法。
功能:
function getPlatformaIme($pids) {
$platforme[] = explode(',', $pids);
$this->loadModel('Gamer.Platforme');
foreach($platforme as $pid) {
$names = $this->Platforme->find('list', array(
'conditions' => array(
'Platforme.id' => $pid
)
));
}
return implode(', ', $names);
}
这给出了数据库中的名称,如果数组是 (1,2) 返回 (PC, PS3)