1
votes

I have created simple controller, set routing and everything works, until I add the routing for the third link. Then I got an error

Cannot import resource "C:\xampp\htdocs\Symfony\src\Acme\Bundle\WebBundle/Resources/config/routing.yml" from "C:/xampp/htdocs/Symfony/app/config\routing.yml".

DefaultController.php:

<?php

namespace Acme\Bundle\WebBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class DefaultController extends Controller
{
public function indexAction()
{
    return $this->render('AcmeWebBundle:Default:index.html.twig');
}


//* find a ride *//

public function findAction()
{

    return $this->render('AcmeWebBundle:Default:find.html.twig');

}

//*book a ride *//

public function bookAction()
 {

    return $this->render('AcmeWebBundle:Default:book.html.twig');
  }
}

This is part of the master.html.twig where is the simple navigation.

  ...
   <div id="left1"><a href="{{ path('acme_web_homepage') }}"><strong>Home</strong></a>
     </div>
     <div id="left2">
     </div>
     <div id="left3"><a href="{{ path('find') }}"><strong>Find a ride</strong></a>
     </div>
     <div id="left4">
     </div>
     <div id="left5"><a href="{{ path('book') }}"><strong>Book a ride</strong></a>
     </div>

and the routing.yml file

acme_web_homepage:
    pattern:  /home
    defaults: { _controller: AcmeWebBundle:Default:index }

find:
    pattern: /find
    defaults: { _controller: AcmeWebBundle:Default:find }
book:
    pattern: /book
    defaults: { _controller: AcmeWebBundle:Default:book }

If I remove the route for the book path everything works fine. Where am I wrong?

4

4 Answers

4
votes

Yaml is based on indentation. You must indent all properties of book with some spaces (I recommend 4 spaces):

book:
    pattern: /book
    defaults: { _controller: AcmeWebBundle:Default:book }

More information about the Yaml Format in the documentation.

2
votes

The yml files must be indented by 4 spaces.

book:
    pattern: /book
    defaults: { _controller: AcmeWebBundle:Default:book }
0
votes

Finaly i figure out what was the problem:

I have left space with pressing the tab button. No matter how weird this will sound i replace that with 4 spaces like @Wouter suggested and everything works fine.

Next time forget the tab, when working with yml files.

0
votes

I noticed some weird Symfony behaviour during import. When services are defined in config/services.yaml file, they are loading properly, but when I configure them in config/services/services.yaml, (after import from config/services.yaml) they start give error like

Cannot autowire service "App\Command***\XyzCommand": argument "$env" of method "__construct()" is type-hinted "string", you should configure its
value explicitly.