我正在尝试将文章相互链接。该方案定义如下
参加文章A,B和C.
我的代码:
public function executeLinkarticle(sfWebRequest $request) {
$this->articleId = $request->getParameter('id');
if ($request->isMethod('POST')) {
$articles = $request->getParameter('articles');
$articleId = $request->getParameter('articleId');
foreach ($articles as $linkedArticleId) {
//Linking A To B
$linkedArticleObj = new BlogArticleLinkedArticle();
$linkedArticleObj->setArticleId($articleId);
$linkedArticleObj->setLinkedArticleId($linkedArticleId);
$linkedArticleObj->save();
//Linking B To A
$linkedArticleObj = new BlogArticleLinkedArticle();
$linkedArticleObj->setArticleId($linkedArticleId);
$linkedArticleObj->setLinkedArticleId($articleId);
$linkedArticleObj->save();
//linking C to A code
Checking the Database Table IF B is LINKED WITH A(i.e already linked) THEN how to link C to A ?
}
return $this->renderText();
}
}
表格结构
ID | ARTICLE_ID | LINKED_ARTICLE_ID