Symfony 2.7 - 在控制器中使用实体

时间:2018-01-03 13:25:24

标签: symfony symfony-2.7

我正在使用Symfony 2.7和自定义捆绑包:

  • 3个实体:下载(),信息()和用户()
  • 1个控制器:MainController.php

我没有"使用Mycompany \ Bundle \ Mycustombundle \ Entity \ [...]"在我的控制器顶部,但如果我测试:

<?php

namespace Mycompany\Bundle\Mycustombundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

class MainController extends Controller
{


    public function listAction()
    {

        [... misc. operations ...]
        [... misc. operations ...]
        [... misc. operations ...]

        $this->getDoctrine()->getManager()->getRepository('Mycustombundle:Download');

        [... misc. operations ...]

        $new_download = new Download();
        // WORKS

        $this->getDoctrine()->getManager()->getRepository('Mycustombundle:Info');

        [... misc. operations ...]

        $new_info = new Info();
        // WORKS

        $new_user = new User();
        // FATAL ERROR 500
        // In logs : Attempted to load class "User" from namespace "Mycompany\Bundle\Mycustombundle\Controller". Did you forget a "use" statement for another namespace?

        [... misc. operations ...]
        [... misc. operations ...]
        [... misc. operations ...]

    }

}

?>

怎么可能?是因为我使用下载和信息的存储库吗?

0 个答案:

没有答案