table: USERS
| id | name | city_id |
| 1 | jonh | 1 |
table: CITY
| id | city_ name |
| 1 | London |
在action.class
獲得ID爲其他表:在Symfony的
$this->user_list = Doctrine::getTable('Users')
->createQuery('a')
->execute();
,這產生:
$user_lists->getId();
$user_lists->getName();
$user_lists->getCityId();
| 1 | john | 1 |
我怎樣才能讓:
| 1 | jonh | London |
?
我做出UsersTableClass:
public function getCityName($id) {
$q = $this->createQuery('j')
->select('u.name, c.city_name')
->from('Users u')
->where('city_id = ?', $id)
->leftJoin('u.city c');
return $q->fetchOne();
}
$user_lists->getId();
$city_name;
$user_lists->getCityId();
和action.class:
$this->user_list = Doctrine::getTable('Users')
->createQuery('a')
->execute();
$this->city_name = Doctrine::getTable('Users')->getCityName($this->user_list->getCityId());
然後我有錯誤:
Fatal error: Call to undefined method Doctrine_Collection::getCityId()
的感謝!這很好! –