【发布时间】:2016-11-02 15:32:29
【问题描述】:
我是 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(),
));
}
}
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);
}
[...]
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;
}
}
?>
还有我的目录树:
谁能帮我找出我的错误?
谢谢你:)
【问题讨论】:
标签: symfony