doulian4467 2018-01-03 10:21
浏览 47

呈现新模板symfony 4时出现FileLoaderLoadException

I am new and trying to enhance my knowledge to this framework. Having a difficulty in rendering a template, it gives me an error:

FileLoaderLoadException ERROR 64] XML declaration allowed only at the start of the document (in n/a - line 2, column 6) in C:\xampp\htdocs\symfony\configoutes/routes.xml (which is loaded in resource "C:\xampp\htdocs\symfony\configoutes/routes.xml")

Controller

<?php

namespace App\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

class UserController extends Controller
{
    /**
     * @Route("/homepage", name="user")
     */
    public function index()
    {
        return $this->redirectToRoute('homepage');
    }
}

YAML

user:
    path:     /homepage
    controller: App\Controller\UserController::index

XML

<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/routing
        http://symfony.com/schema/routing/routing-1.0.xsd">

    <route id="user" path="/homepage">
        <default key="_controller">App\Controller\Userontroller::index</default>
    </route>
</routes>

Question: How can I solve this? Is there something I missed causing this error?

  • 写回答

1条回答 默认 最新

  • dongsou3041 2018-01-03 13:52
    关注

    Maybe you don't understand how does works the routing in Symfony and It's normal for newcomers.

    Routing is very easy, you have to define it (in yaml OR XML OR PHP OR annotations) not All just one of them :-).

    The best practices recommend to use annotations so comment your yaml and remove XML files and follow the documentation

    /**
     * @Route("/homepage", name="user")
     */
    

    /homepage means that this url matches this function and name="user" It's the path name in twig like this

    <a href="{{ path('user') }}">User page</a>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害