2015-09-18 28 views
0

呈現模板我有一個函數在我的控制器是這樣的:爲什麼symfony中找不到它的其他功能

<?php 

namespace GradeBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; 
use Symfony\Component\HttpFoundation\Response; 
use Symfony\Component\HttpFoundation\Session\Session; 
use GradeBundle\Entity\User; 
use GradeBundle\Entity\SchoolClass; 

class MainController extends Controller 
{ 
/** 
* @Route("/", name="index_page") 
*/ 
public function index() 
{ 

    return $this->render('GradeBundle:Default:index.html.twig'); 

} 

它正確地呈現樹枝模板。然而,當我使用其他功能:

/** 
    * @Route("/adminNew", name="add_admin") 
    */ 

    public function addAdmin() 
    { 
     $session = new Session(); 

     if($session->get('loggedIn') == null) 
     return $this->redirect($this->generateUrl('index_page')); 
     else 
     return $this->render('GradeBundle:Add:newAdmin.html.twig'); 

    } 

我有以下錯誤:

Unable to find template "GradeBundle:Default:index.twig.html". 

沒有任何人有任何想法可能是錯誤的?

+0

它不應該是的indexAction和addAdminAction? –

回答

0

這是一個錯字的地方調用模板:

GradeBundle:Default:index.twig.html 

但是你只有GradeBundle:Default:index.html.twig模板。

注意區別:html.twigtwig.html

我懷疑你在GradeBundle:Add:newAdmin.html.twig擴展它:

{% extends 'GradeBundle:Default:index.twig.html' %} 

,但應該是:

{% extends 'GradeBundle:Default:index.html.twig' %}  
0

您是否確保爲您使用的控制器使用正確的命名空間?你是否包含正確的文件?另外我不確定我是否正確理解了這個問題 - 你是否在說如果使用不同的枝文件渲染器添加另一個函數,第一個函數不再渲染?我可以看到你的類名和命名空間/使用語句嗎?

通常在這些情況下,就是模板位於錯誤的位置,或者不包含正確的文件以便找到它。

邁克爾

相關問題