douhu4091 2016-03-22 18:42
浏览 40
已采纳

在链配置的命名空间StudentsBundle \ Entity中找不到类“ScheduleBundle \ Entity \ schedule”

I am making a application with multiply bundels and database connections.

I keep getting this error: The class 'ScheduleBundle\Entity\schedule' was not found in the chain configured namespaces StudentsBundle\Entity 500 Internal Server Error - MappingException

Here is the code from the controller

<?php
namespace ScheduleBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

//Json Response
use Symfony\Component\HttpFoundation\JsonResponse;

//Class Controller
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

//Request
use Symfony\Component\HttpFoundation\Request;

use ScheduleBundle\Entity\schedule;

class ApiController extends Controller
{
  /**
   * @Route("/api/{week}")
   */
  public function roosterApi(Request $request, $week)
  {
    $rooster = array('week' => '1');


    $entityManager = $this->get('doctrine')->getManager();
    $roosterConnection = $this->get('doctrine')->getRepository('ScheduleBundle:schedule', 'schedule');
    $dataRooster = $roosterConnection->findOneByStudentId('36838');


    $dataRooster->setSchedule($rooster);

    $entityManager->persist($dataRooster);
    $entityManager->flush();

    $out = array('1' => $week);

    return new JsonResponse($out, 200, array('Content-Type' => 'application/json'));
  }
}

?>

I think the problem is with my orm mapping so i include the doctrine code from config.yml

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: StudentDB
        connections:
            StudentDB:
                driver:   '%database_driver%'
                host:     '%database_host%'
                port:     '%database_port%'
                dbname:   '%database_students%'
                user:     '%database_user%'
                password: '%database_password%'
                charset:  UTF8
            TeacherDB:
                driver:   '%database_driver%'
                host:     '%database_host%'
                port:     '%database_port%'
                dbname:   '%database_teachers%'
                user:     '%database_user%'
                password: '%database_password%'
                charset:  UTF8
            GradesDB:
                driver:   '%database_driver%'
                host:     '%database_host%'
                port:     '%database_port%'
                dbname:   '%database_grades%'
                user:     '%database_user%'
                password: '%database_password%'
                charset:  UTF8
            ScheduleDB:
                driver:   '%database_driver%'
                host:     '%database_host%'
                port:     '%database_port%'
                dbname:   '%database_schedule%'
                user:     '%database_user%'
                password: '%database_password%'
                charset:  UTF8
            SpecialGroupDB:
                driver:   '%database_driver%'
                host:     '%database_host%'
                port:     '%database_port%'
                dbname:   '%database_specialgroup%'
                user:     '%database_user%'
                password: '%database_password%'
                charset:  UTF8
            ToDoListDB:
                driver:   '%database_driver%'
                host:     '%database_host%'
                port:     '%database_port%'
                dbname:   '%database_todolist%'
                user:     '%database_user%'
                password: '%database_password%'
                charset:  UTF8

    orm:
        default_entity_manager: students
        entity_managers:
            students:
                connection: StudentDB
                mappings:
                    StudentsBundle:  ~
            teachers:
                connection: TeacherDB
                mappings:
                    TeachersBundle: ~
            grades:
                connection: GradesDB
                mappings:
                    GradesBundle:  ~
            schedule:
                connection: ScheduleDB
                mappings:
                    ScheduleBundle: ~
            specialgroup:
                connection: SpecialGroupDB
                mappings:
                    SpecialGroupBundle:  ~
            todolist:
                connection: ToDoListDB
                mappings:
                    ToDoListBundle: ~

I am using symfony 3.0.3 and doctrine

edit: changed use ScheduleBundle\Entity to use ScheduleBundle\Entity\schedule this did not fix the problem

  • 写回答

1条回答 默认 最新

  • douba2011 2016-03-22 20:31
    关注

    You need to use the correct doctrine entity manager service. In your code you refer to the doctrine service which is an alias of the default entity manager. For the schedule entity manager you need to use the following service:

    doctrine.orm.schedule_entity_manager
    

    So try using this:

    $this->get('doctrine.orm.schedule_entity_manager')
    

    Instead of this:

    $this->get('doctrine')
    

    For dump current service definition you can use the console command:

    app/console debug:container |grep entity
    

    Hope this help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂