我已经阅读了有关此问题的其他问题,但尚未找到解决方案.
我收到以下错误消息:
在链配置>命名空间ZfcUser\Entity,Common\Entity,Employment\Entity,Intern\Entity,> Team\Entity,PurchaseRequest\Entity中找不到类'Doctrine\ORM\EntityManager'.
我有一个HolidayEntity,HolidayController,HolidayService.
添加假期有效,但当我尝试删除假期时,会弹出错误.我将假日id从控制器传递给服务,然后服务取出相关对象并运行doctrine 2 removeEntity命令.
我不确定如何解决这个问题.
控制器代码:
public function deleteAction()
{
$holidayId = $this->params()->fromRoute('id', 0);
try {
$this->getServiceLocator()->get('holidayService')->removeHoliday($holidayId);
} catch (Exception $e) {
$this->flashMessenger()->addErrorMessage($e->getMessage() . '<br>' . $e->getTraceAsString());
}
return $this->redirect()->toRoute('holiday/list');
}
Run Code Online (Sandbox Code Playgroud)
服务代码:
public function removeHoliday($holidayId)
{
try{
$holiday = $this->findOneHolidayById($holidayId);
$this->removeEntity($holiday);
} catch (Exception $e) {
var_dump($e);
}
}
protected function removeEntity($entity)
{
$this->getEntityManager()->remove($entity);
$this->getEntityManager()->flush();
}
Run Code Online (Sandbox Code Playgroud)
代码在"$ this-> getEntityManager() - > remove($ entity)"方法中断.
我已经创建了2个新实体,并且在运行命令'php app / console doctrine:schema:update --dump-sql'时收到消息“没有更新-您的数据库已经与当前实体元数据同步”。
我尝试清除缓存,并删除orm的doctrine文件夹的内容,这是该论坛上的一些建议。仍然没有喜悦。我在配置中使用APC缓存设置,如下所示。
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
metadata_cache_driver: apc
result_cache_driver: apc
query_cache_driver: apc
Run Code Online (Sandbox Code Playgroud) 我有一个很原始的问题:
我在Symfony App中创建了一个实体:
SRC /的appbundle /型号/条/ Article.php:
<?php
namespace AppBundle\Model\Article;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="articles")
*/
class Article {
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length="255", nullable=false)
*/
private $name;
}
Run Code Online (Sandbox Code Playgroud)
当我输入控制台时:
php app/console doctrine:generate:entities AppBundle
Run Code Online (Sandbox Code Playgroud)
它打印:
Bundle "AppBundle" does not contain any mapped entities.
Run Code Online (Sandbox Code Playgroud)
当我输入:
php app/console doctrine:generate:entities AppBundle/Model/Article/Article
Run Code Online (Sandbox Code Playgroud)
它打印:
Class "AppBundle\Model\Article\Article" is not a …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行一个获取关联对象,如文档symfony 2中所示.它向我显示了一个错误,如标题这篇文章.我做错了什么?
public function indexAction( )
{
$UserRepo = $this->getDoctrine()->getRepository('UserUserBundle:User');
$all = $UserRepo->findOneBy(array('username'=>'macq'));
$allOwner = $all->getOwner()->getName();
return array(
'allOwner'=>$allOwner,
);
}
Run Code Online (Sandbox Code Playgroud)
}
/**
* @ORM\ManyToOne(
* targetEntity ="User\UserBundle\Entity\User",
* inversedBy ="owner"
* )
* @ORM\JoinColumn(
* name = "user_id",
* referencedColumnName ="id",
*
* )
*/
protected $user;
**
* @ORM\OneToMany(
* targetEntity ="Property\ManagementBundle\Entity\Owner",
* mappedBy ="user"
* )
*/
protected $owner;
Run Code Online (Sandbox Code Playgroud) 我正在努力学习Symfony的基础知识,并遇到了令我困惑的问题.
我正在尝试将数据写入SQL表,主要是遵循文档中的说明(http://symfony.com/doc/current/book/doctrine.html).我创建了一个实体
$ php bin/console doctrine:generate:entity
Run Code Online (Sandbox Code Playgroud)
它正确映射到我的数据库表,我可以读写,没问题.之后,我在表格中添加了一列,并向我的实体添加了相应的行:
/**
* @var string
*
* @ORM\Column(name="User_Credentials", type="text")
*/
private $userCredentials;
Run Code Online (Sandbox Code Playgroud)
然后我尝试创建setter和getter,但没有进行任何更改,只是我的Entity的备份.所以我自己添加了getter和setter,但是当尝试写入DB时,相应的列被省略,保持为空.没有错误.我检查并重新检查了拼写错误或其他sytax错误,但找不到任何错误.做的时候
$ php bin/console doctrine:schema:update --dump-sql
Run Code Online (Sandbox Code Playgroud)
我明白了
ALTER TABLE st_users DROP User_Credentials;
Run Code Online (Sandbox Code Playgroud)
所以看来我的专栏完全被忽略了.我重新清理了缓存,没有改变任何东西.显然,我迷路了.任何关于正确路径的提示都将受到赞赏.
谢谢.
我试图在我的数据库中插入json数据与doctrine由于某种原因我无法在数据库中插入数据
这是我的代码
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)
{
//
//
// print_r($rooster);
//
// echo 'Rooster: ' . $dataRooster->getSchedule();
$rooster = array('week' => '1');
$roosterConnection = $this->get('doctrine')->getRepository('ScheduleBundle:schedule', 'schedule');
$dataRooster = $roosterConnection->findOneByStudentId('36838');
$dataRooster->setSchedule($rooster);
$out = array('1' => $week);
return new JsonResponse($out, 200, array('Content-Type' => 'application/json'));
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的实体
namespace ScheduleBundle\Entity;
use Doctrine\ORM\Mapping as …Run Code Online (Sandbox Code Playgroud) Produto.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Produto
*
* @ORM\Table(name="produto")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProdutoRepository")
*/
class Produto
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="descricao", type="string", length=50)
*/
private $descricao;
/**
* @ORM\ManyToOne(targetEntity="Categoria", inversedBy="produtos")
* @ORM\JoinColumn(name="categoria_id", referencedColumnName="id")
*/
private $categoria;
/**
* @var decimal
*
* @ORM\Column(name="valor", type="decimal", scale=2)
*/
private $valor;
/**
* @var int
*
* @ORM\Column(name="multiplo", type="integer")
*/
private $multiplo;
/** …Run Code Online (Sandbox Code Playgroud) 我有问题,因为我没有创建数据库
我的parameters.yml
parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt
Run Code Online (Sandbox Code Playgroud)
请帮帮我 :)
我有一个关于symfony学说的片段,它按降序选择数据.尝试将where子句应用于某些等于true的字段是一个问题.以下是我的片段
$results = $this->getDoctrine()->getRepository('RealBundle:Foo')->findBy([], ['id' => 'DESC','active' => true]);
Run Code Online (Sandbox Code Playgroud)
我有一个名为active的字段.检索active为true的所有结果是一个挑战
上述尝试给出了错误
为RealBundle\Entity\Foo #active指定的方向顺序无效
这里是symfony的新手
我的计算机中有两个连接设置config/packages/doctrine.yaml。
Connection 1 is default; //connects to localhost:mysql:root:password:local_db
Connection 2 is remote; // connection to a server xxx.xxx.xx.xxx.:username:pwd:remote_db
Run Code Online (Sandbox Code Playgroud)
是否可以使用cli工具生成Entity类,php bin/console make:entity Product以在自定义目录中生成实体。
当我运行上述命令时,“ Product”实体类在我的src/Entity/目录中生成,但我希望根据我们的需要生成它,
所以可以说在场景1中,我希望它在src/Entity/Customer/目录中生成Entity类,
在方案2中,我希望它在src/Entity/Products/目录中生成Entity类。如果我能够做到这一点,那么迁移和实体映射对我来说将变得容易得多。