Tag:
columns:
name:
type: string(100)
TagNews:
columns:
tag_id:
type: integer
primary: true
news_id:
type: integer
primary: true
relations:
Tag: { onDelete: CASCADE, local: tag_id, foreign: id }
News: { onDelete: CASCADE, local: news_id, foreign: id }
News:
columns:
tag_id:
type: integer
name:
type: string(100)
relations:
Tag:
class: Tag
refClass: TagNews
local: news_id
foreign: tag_id
foreignAlias: TagNews
TAG:
| id | name |
| 1 | tag1 |
| 2 | tag2 |
| 3 | tag3 |
TagNews:
| id_tag | tag_news |
| 1 | 1 |
| 2 | 1 |
| 2 | 2 |
| 3 | 2 |
| 3 | 3 |
| 1 | 3 |
News:
| id | name |
| 1 | news1 |
| 2 | news2 |
| 3 | news3 |
| 4 | news4 |
| 5 | news5 |
如何获取tag1等的所有新闻?
例如 site.com/tag/tag1 ? 我必须在action.class和模板中写什么?我使用Symfony 1.4和Doctrine 1.2
答案 0 :(得分:1)
$tag = TagTable::getInstance()->find(1);
$news = $tag->getNews();
应该有效..否则你必须在标签中定义与新闻的关系(与新闻中的标签相同)