B
B
BonBon Slick2017-11-24 00:21:50
symfony
BonBon Slick, 2017-11-24 00:21:50

Writes that the controller is not found?

I do according to symfony.com/doc/current/quick_tour/the_big_picture.html
Error:

The autoloader expected class "App\AppBundle\Controller\DefaultController" to be defined in file 
"/home/vagrant/Code/testsite/vendor/composer/../../src/AppBundle/Controller/DefaultController.php". The file was found but
 the class was not in it, the class name or namespace probably has a typo in 
/home/vagrant/Code/testsite/config/services.yaml (which is loaded in resource 
"/home/vagrant/Code/testsite/config/services.yaml").


controller

<?php
namespace AppBundle\Controller;

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

class DefaultController extends Controller
{
    public function indexAction()
    {
        $welcome = 'Hello World!';
        $this->render('index.html.twig', array(
            'welcome' => $welcome,
        ));
    }
}

route:
# config/routing.yml
index:
    path:     /
    defaults: { _controller: AppBundle:DefaultController:index }

The view lies where it should
. Tried it like this:
/**
     * @Route("/", name="homepage")
     */
    public function indexAction()
    {

I think the configs are acting up, or Windows as usual. Can't clear cache

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
padlyuck, 2017-11-24
@BonBonSlick

The autoloader expected class "App\AppBundle\Controller\DefaultController" namespace was written somewhere in a curve. in the controller you showed the namespace AppBundle\Controller\DefaultController

I
ipokos, 2017-11-24
@ipokos

I'm not sure what is connected and that this is the right solution, but there was the same situation when I did it following the example of the default bundle (src/AppBundle/...)
I did src/Vendor/NameBundle/... and everything is ok.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question