Php 如何列出某个作者在symfony中写的文章?
我在开发一个简单的新闻web应用程序 它包括表项目(id、标题、内容、用户id)和表用户(id、名称、用户名、密码..)等 在后端应用程序中,我只想列出具有特定Php 如何列出某个作者在symfony中写的文章?,php,symfony1,symfony-1.4,backend,Php,Symfony1,Symfony 1.4,Backend,我在开发一个简单的新闻web应用程序 它包括表项目(id、标题、内容、用户id)和表用户(id、名称、用户名、密码..)等 在后端应用程序中,我只想列出具有特定用户id的文章 我将从$this->getUser()->getAttribute('user\u id')获得user\u id 据我所知,symfony网站上提供的文档并未涵盖此问题。将为您提供不同的方法 根据您的需要,您可以覆盖buildQuery: protected function buildQuery() { retur
用户id
的文章
我将从$this->getUser()->getAttribute('user\u id')
获得user\u id
据我所知,symfony网站上提供的文档并未涵盖此问题。将为您提供不同的方法
根据您的需要,您可以覆盖buildQuery
:
protected function buildQuery()
{
return parent::buildQuery()
->where('user_id = ?', $this->getUser()->getAttribute('user_id'));
}
你可以:
- 在generator.yml中,在like下插入新行:
list: title: Articles list table_method: getArticlesByUserId
- 在ArticleTable.class.php中插入一个新函数:
public function getArticlesByUserId() { $userId = sfContext::getInstance()->getUser()->getAttribute( 'user_id' ); $u = $this->createquery( 'u' )->where( 'u.user_id = ?', $userId ); return $q; }