2017-04-05 78 views
0

我正在使用symfony 3.2.4(使用控制檯--version) 我正在使用openclassroom教程 控制器總是提前返回下面的錯誤。 不過,下面的文件,存在並且可以訪問。symfony 3.2.4 ...無法找到模板「OCPlatformBundle:Advert:index.html.twig

src/OC/PlatformBundle/Resources/views/Advert/index.html.twig

我瘋了這一點。是否有人有想法?

感謝。

<?php 
// src/OC/PlatformBundle/Controller/AdvertController.php 
namespace OC\PlatformBundle\Controller; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Response; 
class AdvertController extends Controller 
{ 
    public function indexAction() 
    { 
    $content = $this->get('templating')->render('OCPlatformBundle:Advert:index.html.twig'); 

    return new Response($content); 
    } 
} 

無法找到模板 「OCPlatformBundle:廣告:index.html.twig」 (看着:在/ var/www/html等/ symfony中/應用/資源/視圖, 在/ var/www/html等/ symfony中/供應商/ symfony中/ symfony中/ src目錄/ Symfony的/橋樑/嫩枝/資源/視圖/表)。

*

+2

這幾乎就像你bundle沒有在'AppKernel'中註冊,但這沒有意義,不是嗎? –

+0

不要忘記清理緩存! (樹枝必須通過symfony編譯爲php並存放在緩存中) – goto

+0

是的註冊和控制器正在工作,而它返回一個字符串響應,而不是渲染內容。我通過控制檯清理緩存(這很好,因爲我必須替換/ var/dev文件夾中的777),但是這不會改變任何....:/ – totofgo

回答

0

你嘗試在app/Resources/views/Advert/index.html.twig創建模板?

這是一個更好的做法:Store all your application's templates in app/Resources/views/ directory.(從SF DOC)...

那麼,你就可以通過這種方式 「呼」 是:

/***/ 
public function indexAction() 
{ 
    return $this->render('Advert/index.html.twig', []); 
} 
/***/