69

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.

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

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}
halfer
  • 19,824
  • 17
  • 99
  • 186
odbhut.shei.chhele
  • 5,834
  • 16
  • 69
  • 109
  • 1
    Please provide more information. What did you tried? Which error is throwed? And post the router:debug output. And at least, I don't get your title... – Pi Wi Nov 14 '13 at 11:06
  • This question was lacking an [mcve] (no error information) but I assume the title was the error. I've added that now. – halfer Feb 20 '18 at 18:33

4 Answers4

103

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:

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.

(source: YAML FAQ (thanks to Destiny Architect for the link))

For example, the Symfony configuration file can be written with 2 or 4 spaces as indentation:

4 spaces

doctrine:
    dbal:
        default_connection: default

2 spaces

doctrine:
  dbal:
    default_connection: default
A.L
  • 10,259
  • 10
  • 67
  • 98
  • 1
    http://yaml.org/faq.html gives apparent official answer to “Why does YAML forbid tabs?”, and I tend to concur, indeed, inspired by this, have then been doing the same in the other programming languages I code. – Destiny Architect Nov 08 '14 at 22:57
  • @Destiny Architect thanks, I'll add it to the answer. – A.L Nov 08 '14 at 23:01
  • 7
    So how does a parser know if the file is using two or four spaces per indentation level? What if a file mixes the two? How will the parser validate the file? And what happens if it encounters three spaces? – Oscar Sep 05 '16 at 08:49
  • @Oscar I don't know. Did you try to mix 2 and 4 spaces? 3 spaces should trigger an error. – A.L Sep 05 '16 at 09:03
  • 10
    No. I haven't used a YAML parser yet. I was wondering if anyone else knew, because the insistence on spaces seems to increase ambiguity rather than decrease it. – Oscar Sep 06 '16 at 06:20
  • @Oscar: about the 2 or 4 spaces, if think that it's simple : the spaces in front of `dbal` indicates that this is an array. Since `doctrine` was the root, `dbal` can only be the first level. So YAML can count the spaces before the first level and know if there is 2 or 4 spaces on each line. – A.L Sep 06 '16 at 12:42
  • 1
    What happens if the first indentation is two spaces, and the second one is four spaces? Does the parser flag an error because a level appears to be missing? – Oscar Sep 07 '16 at 09:37
  • 118
    @DestinyArchitect It's a fallacious argument. Bad code will always look bad. Tabs are not the cause of bad identation. Tabs look being customizable and using less bytes makes them better than spaces. And every argument for spaces can be debunked. Present me any code and I'll give you a nicely formatted one using only tabs. – Kulvar Mar 06 '19 at 16:26
  • 99
    Using tabs is a headache only for people who can't use them properly. – Youda008 Apr 30 '19 at 09:17
  • 79
    this is the biggest mistake of guido... he should have outlawed the space indentation ;) – yota May 18 '19 at 19:07
  • 27
    Time to add examples with all flavors of space fans indentations: 1, 3, 6, 8, . Some people just can't understand simplest abstract things like tabs. – Victor Yarema Jan 15 '20 at 20:05
  • 33
    The answer is correct, so I upvoted it, but the argument is very bad. Problems do only occur, if tab and space indentation is mixed in one file. This should be forbidden. Otherwise it is perfectly and easily possible to treat all tabs in a tabs-only indented file as one would treat single-space-indentation. The actual reason must be incompetence or personal preference. The latter is not a problem at all, but not saying it is just pathetic. I'm disappointed, especially because I think YAML is otherwise brilliant. – Neonit Jan 30 '20 at 16:34
  • @amcgregor: great points! For the sake of argument, then let's just state the "lowest common denominator" between Python and YAML: both have _sintatically meaningful whitespace_, even if in Python that's just for indentation. It sets both apart from, say, C and Java. – MestreLion Nov 28 '21 at 11:43
  • 5
    Guido was green at the time. Tabs are not only more manageable as indentation, but require fewer keystrokes to code and navigate, and reduce the file size/payload. – ekerner Jan 23 '22 at 13:51
  • @Neonit Indeed. I went to check the latest YAML spec, and it has this odd contradiction at the beginning of Chapter 6: "To maintain portability, tab characters must not be used in indentation..." then goes on to say two sentences later, "The amount of indentation is a presentation detail and must not be used to convey content information." Maybe I'm missing some nuance, but it sounds condtradictory to say indentation shouldn't be used to convey content information, but also it could ruin portability. – Angelo Mar 12 '23 at 23:33
7

IF you are using EditorConfig make sure to add this to your .editorconfig file

[*.yml]
indent_style = space
indent_size = 4

you can change indent_size to 2, depends on your preferences

chebaby
  • 7,362
  • 50
  • 46
  • 2
    I wonder: since "indent_size" is a **user** preference, should it be included in the file at all? – Andreas Linnert Jul 03 '19 at 09:14
  • 8
    No, and this is an argument for tab indentation: using tabs, each member of the team can see the indentation according to their preference, while using tabs, everyone working on the same code base should be consistent – Alireza Aug 21 '19 at 11:57
  • instead of encoding the file format in metadata use a vim modeline in a comment near the top of the file – Jasen Aug 06 '20 at 00:55
  • 1
    @Jasen i disagree, a unified editorconfig file is much cleaner than inserting editor-specific comments into every file. – alexia Nov 13 '22 at 19:54
  • is if you are the only developer, sure alter your environment to suit your work. if you are not. expect pushback, vim modelines are supported by most edittors hardly editor specific. – Jasen Nov 13 '22 at 23:34
3

Can you try cache:clear or try using path instead of pattern.

The path option is new in Symfony2.2, pattern is used in older versions.

community_online_shop_homepage:
    path: /
    defaults: { _controller: CommunityOnlineShopBundle:Page:index }
_login:
    path: /login
    defaults: { _controller: CommunityOnlineShopBundle:Page:login }
Krish R
  • 22,583
  • 7
  • 50
  • 59
0

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 }").

Florian Baierl
  • 2,378
  • 3
  • 25
  • 50
mirihen
  • 11