这很简单!在这里,我使用了FrameworkExtraBundle @Route
注释,其中路由模式简单地以.html
结尾。
<?php
namespace Foo\BarBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class HomeController extends Controller
{
/**
* Demo of a route which includes a .html suffix
*
* @Route("/town/Blah-blah-in-{townName}.html", name="town")
* @Template()
*/
public function townAction($townName)
{
# Lookup $town slug to get a town
# ...
# 404 if town not found
# ...
# just for illustration
$town = $townName;
return array('town' => $town);
}
}
{# src/Foo/BarBundle/Resources/Home/town.html.twig #}
{% extends 'FooBarBundle::layout.html.twig' %}
{% block title %}Blah blah in {{ town }} - {{ parent() }}{% endblock %}
{% block content %}
<h1>Blah blah in {{ town }}!</h1>
<p> and other content from the original /town/Blah-blah-in-{{ town }}.html</p>
{% endblock %}
来源
2015-05-19 17:33:28
jah
http://symfony.com/doc/current/cookbook/templating/render_without_controller.html – smarber
路径可以是几乎任何你喜欢的。点或“html”没有什么特别之处。如果你这样做是为了保留旧网站的URL,那么一些301重定向到清理URL可能是更好的选择。如果你认为.html结尾有助于搜索引擎优化,那么这是多年前一个模糊的未经证实的想法。 – tetranz