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 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)