[英]symfony Template's name in render()
我正在尝试创建登录页面,并且我只想测试Doctrine是否有效,但是我遇到了模板位置的问题,所以这是我的代码
namespace Login\loginBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class LoginController extends Controller
{
public function loginAction()
{
$username="username";
$password="password";
$em=$this->getDoctrine()->getEntityManager();
$repository=$em->getRepository('Login\loginBundle\Entity\Login\Utilisateur');
$user=$repository->findOneBy(array('username'=>$username,'password'=>$password));
if($user){
return $this->render('Login\loginBundle\Resources\views\Default\index.html.twig',array('name'=>$user->getNom()));
}
else{
return $this->render('Login\loginBundle\Resources\views\Default\index.html.twig',array('name'=>'login failed'));
}
}
这是我的模板Login \\ loginBundle \\ Resources \\ views \\ Default \\ index.html.twig的位置
这是我得到的错误:
Unable to find template "Login\loginBundle:Default:index.html.twig".
500 Internal Server Error - InvalidArgumentException
3 linked Exceptions:
Twig_Error_Loader »
InvalidArgumentException »
InvalidArgumentException »
[4/4] InvalidArgumentException: Unable to find template "Login\loginBundle:Default:index.html.twig". +
[3/4] Twig_Error_Loader: Unable to find template "Login\loginBundle:Default:index.html.twig". +
[2/4] InvalidArgumentException: Template name "Login/loginBundle:Default:index.html.twig" is not valid. +
[1/4] InvalidArgumentException: Bundle "Login/loginBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? +
谢谢您帮忙
渲染模板如下:
// {# yourBundle/Resources/views/someFolder/index.html.twig #}
return $this->render(
'someFolder/index.html.twig',
array('variable' => $something)
);
模板字符串的命名不正确。 在您的情况下,应如下所示:
$this->render('@Login/loginBundle/Default/index.html.twig');
我建议您使用带有Symfony2插件的PHPStorm这样的IDE来利用智能感知。
http://symfony.com/doc/current/book/templating.html#referencing-templates-in-a-bundle
$this->render('LoginloginBundle:Default:index.html.twig');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.