首先,请原谅我的英语,我试图努力避免一些错误。
我有一点问题,因为我正在尝试开发我的布局,当我想运行我的网页时,我有这样的错误:
在渲染模板期间抛出异常(" DateTime :: __ construct():无法解析位置0(n)的时间字符串(nom)
这是我的代码:
<?php
//src/OC/PlatformBundle/Controller/AdvertController.php
namespace OC\PlatformBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class AdvertController extends Controller{
Public function indexAction(){
//On ne sait pas combien de pages il y a
//Mais on sait qu'une page doit être supérieur ou égal à 1
//if ($page < 1){
//On déclenche une exception NotFoundHttpException, cela va afficher
//une page d'erreur 404
//throw new NotFoundHttpException('Page "'.$page.'" inexistante.');
//}
//Ici on récupérera la liste des annonces, puis on la passera au template
//
//Mais pour l'instant on ne fait qu'appeler le template
return $this->render('OCPlatformBundle:Advert:index.html.twig', array(
'listAdverts' => array()
));
}
Public function viewAction($id){
//Ici, on récupère l'annonce correspondant à l'id $id
return $this->render('OCPlatformBundle:Advert:view.html.twig', array('id' => $id));
}
我的布局:
{# src/OC/PlatformBundle/Resources/views/layout.html.twig #}
{% extends "::layout.html.twig" %}
{% block title %}
Annonces - {{ parent() }}
{% endblock %}
{% block body %}
{# On définit un sous titre commun à toutes les pages du bundle, par exemple #}
<h1> Annonces </h1>
<hr>
{# On définit un nouveau bloc, que les vues du bundle pourront remplir #}
{% block ocplatform_body %}
{% endblock %}
{% endblock %}
索引:
{# src/OC/PlatformBundler/Resources/views/Advert/index.html.twig #}
{% extends "OCPlatformBundle::layout.html.twig" %}
{% block title %}
Accueil - {{ parent() }}
{% endblock %}
{% block ocplatform_body %}
<h2> Liste des annonces </h2>
<ul>
{% for advert in listAdverts %}
<li>
<a href="{{ path('oc_platform_view', {'id': advert.id}) }}">
{{ advert.title }}
</a>
par {{ advert.author }},
le {{ advert.date|date('d/m/Y') }}
</li>
{% else %}
<li> Pas (encore!) d'annonces </li>
{% endfor %}
</ul>
{% endblock %}
感谢您的帮助。
度过愉快的一天