php YAML 文件不能包含制表符作为缩进
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19975954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
A YAML file cannot contain tabs as indentation
提问by eddard.stark
This is my first work with Symfony 2. All I am trying to do here is whenever the user clicks on the submit button he will go to another page.
这是我第一次使用 Symfony 2。我在这里要做的就是每当用户点击提交按钮时,他就会转到另一个页面。
But my index page isn't loading. They are saying there is something wrong with my routing file, specifically:
但是我的索引页没有加载。他们说我的路由文件有问题,特别是:
A YAML file cannot contain tabs as indentation
YAML 文件不能包含制表符作为缩进
I don't know what I have done wrong. Here is my routing file.
我不知道我做错了什么。这是我的路由文件。
community_online_shop_homepage:
pattern: /
defaults: { _controller: CommunityOnlineShopBundle:Page:index }
_login:
pattern: /login
defaults: { _controller: CommunityOnlineShopBundle:Page:login}
回答by A.L
A YAML file use spaces as indentation, you can use 2 or 4 spaces for indentation, but no tab. In other words, tab indentation is forbidden:
YAML 文件使用空格作为缩进,您可以使用 2 或 4 个空格作为缩进,但不能使用 tab。换句话说,制表符缩进是被禁止的:
Why does YAML forbid tabs?
Tabs have been outlawed since they are treated differently by different editors and tools. And since indentation is so critical to proper interpretation of YAML, this issue is just too tricky to even attempt. Indeed Guido van Rossum of Python has acknowledged that allowing TABs in Python source is a headache for many people and that were he to design Python again, he would forbid them.
为什么 YAML 禁止选项卡?
标签已被取缔,因为它们被不同的编辑器和工具区别对待。而且由于缩进对于正确解释 YAML 非常重要,因此这个问题甚至无法尝试。事实上,Python 的 Guido van Rossum 承认在 Python 源代码中允许 TAB 对许多人来说是一个头疼的问题,如果他再次设计 Python,他会禁止它们。
(source: YAML FAQ(thanks to Destiny Architectfor the link))
(来源:YAML 常见问题解答(感谢Destiny Architect提供链接))
For example, the Symfony configuration filecan be written with 2 or 4 spaces as indentation:
例如,Symfony 配置文件可以写成 2 或 4 个空格作为缩进:
4 spaces
4格
doctrine:
dbal:
default_connection: default
2 spaces
2格
doctrine:
dbal:
default_connection: default
回答by Krish R
Can you try cache:clear
or try using path
instead of pattern
.
您可以尝试 cache:clear
或尝试使用path
代替pattern
.
The path
option is new in Symfony2.2, pattern
is used in older versions.
该path
选项在Symfony2.2 中是新的,pattern
在旧版本中使用。
community_online_shop_homepage:
path: /
defaults: { _controller: CommunityOnlineShopBundle:Page:index }
_login:
path: /login
defaults: { _controller: CommunityOnlineShopBundle:Page:login }
回答by chebaby
IF you are using EditorConfigmake sure to add this to your .editorconfigfile
如果您使用EditorConfig,请确保将其添加到您的.editorconfig文件中
[*.yml]
indent_style = space
indent_size = 4
you can change indent_sizeto 2, depends on your preferences
您可以将indent_size更改为2,具体取决于您的偏好
回答by mirihen
A YAML file cannot contain tabs as indentation, so the mistake is here:
C:\\xampp\\htdocs\\api\\app/../src/AppBundle/Resources/config/valida
tor.yml" at line 9 (near " - { resource: validators/services.yml }")
.
YAML 文件不能包含制表符作为缩进,所以错误在这里:
C:\\xampp\\htdocs\\api\\app/../src/AppBundle/Resources/config/valida
tor.yml" at line 9 (near " - { resource: validators/services.yml }")
.