自动加载器期望的类[...]在文件中定义

Zol*_*oom 6 symfony

我是Symfony 3的新手.我尝试解决我的两个控制器的问题.当我执行indexAction函数时,我遇到了这个错误:

自动加载器期望类"Arcturus\GeomancieBundle\Controller\TirageController"在文件"/Applications/MAMP/htdocs/geomancie2/geomancie/vendor/composer/../../src/Arcturus/GeomancieBundle/Controller/TirageController中定义. PHP的".找到该文件但该类不在其中,类名或命名空间可能有拼写错误.

我发现这可能是班上的一个错字......但没有发现任何错误.

这是我的两个控制器:

DefaultController.php

<?php

namespace Arcturus\GeomancieBundle\Controller;
namespace Arcturus\GeomancieBundle\Entity;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form;
use Symfony\Component\HttpFoundation\Request;
use Arcturus\GeomancieBundle\Entity;

class DefaultController extends Controller
{
    public function indexAction(Request $request) {
        $tirage = new Tirage();
        $formTirage = $this->createFormBuilder($tirage)->getForm();

        // Si le formulaire a été soumis

        $formTirage->handleRequest($request);

        if ($formTirage->isSubmitted() && $formTirage->isValid()) {
            $tirage = $formTirage->all();

            return $this->redirectToRoute('arcturus_geomancie_tirage', $tirage);
        }

        // Si le formulaire n'a pas été soumis

        return $this->render('ArcturusGeomancieBundle:Default:index.html.twig', array(
           'form' => $formTirage->createView(),
        ));
    }
}
Run Code Online (Sandbox Code Playgroud)

TirageController.php

<?php

namespace Arcturus\GeomancieBundle\Controller;
namespace Arcturus\GeomancieBundle\Entity;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class TirageController extends Controller
{
    public function afficherTirageAction(Tirage $tirage)
    {
        // On compte le nombre de points dans chaque chaîne
        $nb_dot_l1 = $this->nbDot($tirage->getLigne1());
        $nb_dot_l2 = $this->nbDot($tirage->getLigne2());
        $nb_dot_l3 = $this->nbDot($tirage->getLigne3());
        $nb_dot_l4 = $this->nbDot($tirage->getLigne4());

        // On vérifie que les 4 chaînes contriennent au moins 1 point
        if ($nb_dot_l1 == 0 or $nb_dot_l2 == 0 or $nb_dot_l3 == 0 or $nb_dot_l4 == 0) {
            // On renvoie sur une page d'erreur
            $this->renderView('@ArcturusGeomancie/Default/erreur_tirage.html.twig');
        }

        // On charge les lignes dans un tableau paire/impaire
        $tab_dots_lines = $this->dots_to_array($nb_dot_l1, $nb_dot_l2, $nb_dot_l3, $nb_dot_l4);
        // On garde ce format pour dessiner la figure
        $data['dessin'] = $tab_dots_lines;
        // On récupère le nom de la figure
        $data['figure'] = $this->get_figure($tab_dots_lines);
        // On récupère l'analyse associée
        $data['analyse'] = $this->get_analysis($data['figure']);

        $this->renderView('@ArcturusGeomancie/Default/tirage.html.twig', $data);
    }
[...]
Run Code Online (Sandbox Code Playgroud)

Tirage.php(实体)

<?php

class Tirage
{
    private $ligne1;
    private $ligne2;
    private $ligne3;
    private $ligne4;

    public function getLigne1()
    {
        return $this->ligne1;
    }

    public function getLigne2()
    {
        return $this->ligne2;
    }

    public function getLigne3()
    {
        return $this->ligne3;
    }

    public function getLigne4()
    {
        return $this->ligne4;
    }
}

?>
Run Code Online (Sandbox Code Playgroud)

和我的目录树:

在此输入图像描述

谁能帮我找到我的错误?

谢谢 :)

Mat*_*alo 12

文件中的命名空间存在问题.

删除行

namespace Arcturus\GeomancieBundle\Entity;
Run Code Online (Sandbox Code Playgroud)

从DefaultController.php和TirageController.php,并将其放在Tirage.php中

<?php

namespace Arcturus\GeomancieBundle\Entity;

class Tirage
{
Run Code Online (Sandbox Code Playgroud)

您可以在此处阅读有关命名空间的更多信息:http://php.net/manual/en/language.namespaces.php