簡體   English   中英

Symfony2路由中的可選參數沒有值

[英]Symfony2 Optional parameter in routing has no value

在Symfony2中定義路線時,我在這個細節上苦苦掙扎

小米路由:

blog:
path: /blog/{page}
defaults: { _controller: ManualRouteBundle:Blog:show, page: 33 }

我的控制器:

<?php
namespace Manual\RouteBundle\Controller ;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class BlogController extends Controller{
    public function showAction($page){

        return $this->render('ManualRouteBundle:Blog:show.html.twig') ;
    }
}

我的觀點:

Blog # {{page}}

當我嘗試使用該地址訪問時

http://test/web/blog 

代替

http://test/web/blog/1

我得到這個錯誤

 Variable "page" does not exist in ManualRouteBundle:Blog:show.html.twig at line 1
500 Internal Server Error - Twig_Error_Runtime 

頁面值不應該是33嗎?

我得到了#symfony的答案,我必須將變量傳遞給視圖。

$this->render() like this: $this->render('show.html.twig', array('page' => $page));

怪異的行為恕我直言。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM