To add a page, follow these steps to access the link "hello": 1. in appAppKernel. add code to the PHP file: {code ...} 2. appconfigrouting. yml {code ...} 3. srcAcmeHelloBundleResourcesconfigrouting. yml {code ...} 4 .... I want to add a page with the access link/hello
The configuration steps are as follows:
1. add the code to the app/AppKernel. php file:
public function registerBundles() {$bundles[] = new Acme\HelloBundle\AcmeHelloBundle();return $bundles;}
2. app/config/routing. yml
acme_hello: resource: "@AcmeHelloBundle/Resources/config/routing.yml" prefix: /
3. src/Acme/HelloBundle/Resources/config/routing. yml
hello: pattern: /hello/{name} defaults: { _controller: AcmeHelloBundle:Hello:index }
4. src/Acme/HelloBundle/Controller/HelloController. php
namespace Acme\HelloBundle\Controller;use Symfony\Component\HttpFoundation\Response;class HelloController { public function indexAction() { return new Response("Hello World"); }}
I almost followed the steps in the document, but there are still some problems:
Cannot import resource "D:/xampp/htdocs/Symfony/app/config\routing.yml" from "D:/xampp/htdocs/Symfony/app/config/routing_dev.yml". (Unable to parse at line 2 (near "resource:"@AcmeHelloBundle/Resources/config/routing.yml"").)
You can create a new bundle and create a new bundle directory under the src/Acme directory:
D:\xampp\php>php d:\xampp\htdocs\Symfony\app\console --namespace=Acme/HelloBundle --format=yml
No effect, so I created it manually.
Reply content:
I want to add a page with the access link/hello
The configuration steps are as follows:
1. add the code to the app/AppKernel. php file:
public function registerBundles() {$bundles[] = new Acme\HelloBundle\AcmeHelloBundle();return $bundles;}
2. app/config/routing. yml
acme_hello: resource: "@AcmeHelloBundle/Resources/config/routing.yml" prefix: /
3. src/Acme/HelloBundle/Resources/config/routing. yml
hello: pattern: /hello/{name} defaults: { _controller: AcmeHelloBundle:Hello:index }
4. src/Acme/HelloBundle/Controller/HelloController. php
namespace Acme\HelloBundle\Controller;use Symfony\Component\HttpFoundation\Response;class HelloController { public function indexAction() { return new Response("Hello World"); }}
I almost followed the steps in the document, but there are still some problems:
Cannot import resource "D:/xampp/htdocs/Symfony/app/config\routing.yml" from "D:/xampp/htdocs/Symfony/app/config/routing_dev.yml". (Unable to parse at line 2 (near "resource:"@AcmeHelloBundle/Resources/config/routing.yml"").)
You can create a new bundle and create a new bundle directory under the src/Acme directory:
D:\xampp\php>php d:\xampp\htdocs\Symfony\app\console --namespace=Acme/HelloBundle --format=yml
No effect, so I created it manually.
I have encountered the yml parsing error caused by using tabs. The first problem is that the file format is incorrect. The second problem is that it is useless to add a namespace. In the console, it should be the create: bundle command followed by namespace and format.
Judging from the error information, the yaml syntax in the file @ AcmeHelloBundle/Resources/config/routing. yml is incorrect. check whether the file is indented or contains non-English spaces.