dqq9695 2015-04-23 14:41
浏览 40
已采纳

symfony模板在render()中的名称

I'm trying to create login page, and i want just to test Doctrine if i'ts working or not but i faced this probleme with template's Location so this is my code

    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'));
    }

} 

This is the Location of my template Login\loginBundle\Resources\views\Default\index.html.twig

and this is the error i got :

    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?   +

thank for your help

  • 写回答

3条回答 默认 最新

  • doushuo2834 2015-04-23 15:10
    关注

    http://symfony.com/doc/current/book/templating.html#referencing-templates-in-a-bundle

    $this->render('LoginloginBundle:Default:index.html.twig');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效