0
<?php
class Tonguetwister extends AppModel {
var $name = 'Tonguetwister';
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'language' => array(
'className' => 'language',
'foreignKey' => 'language_alias',
'dependent'=> true
)
);
}
?>
控制器
<?php
class TonguetwistersController extends AppController {
var $name = 'Tonguetwisters';
var $uses = array('Tonguetwister', 'Language');
function index() {
$this->set('languages', $this->Language->find('all'));
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid tonguetwister', true));
$this->redirect(array('action' => 'index'));
}
$this->set('tonguetwisters', $this->Tonguetwister->find('all', array('conditions' => array('language_alias' => $id))));
}
}
?>
我只希望看到指數語言()有繞口令。我怎樣才能做到這一點?
非常感謝!但是這給了我一個錯誤: 警告(512):SQL錯誤:1054:'where子句'中的未知列'Language.alias'[CORE/cake/libs/model/datasources/dbo_source.php,第684行]。表「languages.alias」與「tonguetwisters.language_alias」有關。 – Dennis
要麼你把'language_alias'拼寫成'language.alias'或者關係定義有問題。 – JJJ
是的,這是我模特中的一個資本錯字。謝謝!它完美的作品。 – Dennis