我正在尝试创建登录页面,我想测试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'));
}
}
这是我模板的位置 登录\ loginBundle \资源\视图\默认\ 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? +
感谢您的帮助
答案 0 :(得分:0)
// {# yourBundle/Resources/views/someFolder/index.html.twig #}
return $this->render(
'someFolder/index.html.twig',
array('variable' => $something)
);
答案 1 :(得分:0)
模板字符串的命名不正确。 在你的情况下,它应该如下:
$this->render('@Login/loginBundle/Default/index.html.twig');
我建议您使用像PHPStorm这样的IDE和Symfony2插件来使用intellisense。
答案 2 :(得分:0)
http://symfony.com/doc/current/book/templating.html#referencing-templates-in-a-bundle
$this->render('LoginloginBundle:Default:index.html.twig');