我遇到了Symfony的問題。Symfony 3的樹枝文件與渲染控制器
我有一個VideoController呈現一個樹枝頁面。
此分支頁面包含另一個具有rendercontroller的分支頁面。使用這個渲染控制器,路由崩潰,它說我用第一個控制器發送的「視頻」變量不存在。怎麼了?
這是爲視頻控制器的代碼:
public function getVideo(Request $request, $id) {
$entityManager = $this->getDoctrine()->getManager();
$video = $entityManager->getRepository('AppBundle:Video')->getVidById($id);
return $this->render('vids/videos.html.twig', ['video' => $video]); //Needs improvements
}
videos.html.twig:
{% block main %}
<center>
<video controls style="width:720px;height:360px;" poster="poster.png">
<source src="{{ video.link }}" type="video/mp4;" codecs="avc1.42E01E, mp4a.40.2" />
</video>
{{ include ("comments/comment.html.twig") }}
</center>
{% endblock %}
comment.html.twig:
{% block comment %}
<br><br>
<center>
{{ render(controller('AppBundle:Video:commentVideo')) }}
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
</center>
{% endblock %}
CommentControl ler:
class CommentsController extends Controller
{
/*
* Check if session is valid. If so, user can comment. SECURITY SYSTEM NEEDS TO BE DEVELOPED!!!
* @Route("/", name="comment")
* @Method({"GET", "POST"})
*/
public function commentVideoAction(Request $request) {
$comment = new Comment();
$form = $this->createFormBuilder($comment)
->add('text', TextType::class)
->add('Invia Commento', SubmitType::class)
->getForm();
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$comment = $form->getData();
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($comment);
$entityManager->flush();
return $this->render('vids/videos.html.twig');
}
return $this->render('vids/videos.html.twig', array(
'form' => $form->createView(),
));
}
}
哪個變量會出錯? –
「video」。我也在問題中插入了這個信息! – ProtoTyPus
您需要將'CommentController'中的變量'$ video'傳遞給模板以及... – DarkBee