我想获得&列出该用户登录的同一个idempresa
下的所有用户。idempresa
与sf_guard_profile
表中的用户相关,是的,我在schema.yml
文件上声明了关系。我想在sfGuardUserTable.class.php
中写一个方法,但我不太确定它会起作用,换句话说,我不知道在哪里触摸或如何处理这个。有谁能告诉我正确的方向吗?这是方法(未完成):
public function getUsersByCompany() {
$user = sfContext::getInstance()->getUser()->getProfile()->getIdEmpresa();
$q = $this->createQuery('g');
return $q;
}
任何建议吗?
使用sfContext::getInstance()通常不是好的做法。阅读这篇文章http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/.
如何添加一个静态方法到您的sfGuardUserTable.class.php
,例如
// libformsfGuardUserTable.class.php
static public function getUsersByIdEmpresa($idempresa)
{
//...
$q->andWhere('idempressa = ?', $idempresa);
return $q->execute();
}
然后在你的控制器或从你需要的地方调用它,例如
// appmyAppmodulesmyModuleactionsaction.class.php
public function executeMyAction() {
$profile = $this->getUser()->getProfile();
$usersRelatedByIdempresa = sfGuardUserTable::getUsersByIdempresa($profile->getIdempresa());
//...
}