Tabella lingua
id name
1 italian
2 english
Tabella utenti
id name languageId
1 pippo 1
2 luca 1
3 duffy 2
Ho la necessità nella _form dell’utente di avere una combo con le lingue possibili.
Attualmente ho fatto così in view/user/_form:
<?php echo $form->dropDownList($model,'languageId', $this->getLanguageOptions()); ?>
Nello UserController per ora, barando ho fatto così:
public function getLanguageOptions() {
$usersArray = array("1"=>"ITaliano","2"=>"ENglish");
return $usersArray;
}
In models/Uuser.php ho impostato, manualmente (a db NON ci sono e non ci possono essere relazioni tra chiavi esterne definite) la relazione così (e non so se ha senso):
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'language' => array(self::BELONGS_TO, 'Language', 'language_id'),
);
}
Come faccio a implementare la getLanguageOptions in modo che legga tutti gli id e i nomi delle lingue ?