2011-10-29 4 views
2

私はそのコンセプトに問題があります:バンドルフォーラム(コメントの表示、新規追加など)をしたいのですが、別のバンドルに表示したい:/ articles/showforum)。 inside/articles/showforumのフォーラムを含めることができますが、リンクは古いものになります(たとえば、新しいトピックを追加するフォームを表示する:/ forum/newtopic)。私は/記事/ showforum /フォーラム/ newtopicのようなsthをしたい - これを達成するためにSymfony 2のようなツールはありますか?symfony 2 - 他のバンドルの中のバンドルからアクションを作ります

答えて

2

ForumBundleのベースルーティングを設定できます。ここでは、アノテーションを使用して:

/** 
* Forum controller 
* 
* @Route("/articles/showforum/forum") 
*/ 
class ForumController extends Controller 
{... 

ベースeditAction方法:

\ForumBundle\ForumController.php 
public function editAction($id) 
{ 
    $this->editCustom(id); 

    return array(
     'entity'  => $entity, 
     'edit_form' => $editForm->createView(), 
     'delete_form' => $deleteForm->createView(), 
    ); 
} 

public function editCustom(id) 
{ 
    $em = $this->getDoctrine()->getEntityManager(); 

    $entity = $em->getRepository('ForumBundle:Topic')->find($id); 

    if (!$entity) { 
     throw $this->createNotFoundException('Unable to find Topic entity.'); 
    } 

    $editForm = $this->createForm(new TopicType(), $entity); 
    $deleteForm = $this->createDeleteForm($id); 
} 

\ArticlesBundle\ForumController.php 
public function editAction($id) 
{ 
    \ForumBundle\Controller\ForumController::editCustom(id); 

    return array(
     'entity'  => $entity, 
     'edit_form' => $editForm->createView(), 
     'delete_form' => $deleteForm->createView(), 
    ); 
} 
+0

しかし、私はまた、/写真/ showforumを持つようにしたい場合は?そして、URLの問題を解決しません(フォーラムには/ forum/newtopic、/ forum/replyなどのリンクがあります)、コンテナであるバンドルを指して、forumcontrollerにリダイレクトされます) – chris

+1

その後、アプローチを変更する必要があります。他のバンドルに組み込むことなく使用するかのように、ForumBundleを作成してください。彼のコントローラーで必要なすべてのメソッドをPhotosBundle(ArticlesBundleと同じ)を作成するよりも、名前空間のおかげでForumBundleのメソッドを呼び出すよりも。 – dlondero

+0

しかし、ForumBundleテンプレートのリンクはどうですか?彼らは常にForumBundleメインテンプレート(ForumBundleテンプレートを含むArtcilesBundleテンプレート)にリダイレクトします。 – chris

関連する問題