【问题标题】:symfony2 error automatically create getters and setterssymfony2错误自动创建getter和setter
【发布时间】:2016-10-19 11:26:39
【问题描述】:

我从 Symfony 2 开始,我正在学习一个教程。 教程很完美,但有点细节。

我在 TiendaBundle 文件夹中有一个实体 Tienda.php,它具有属性和良好的映射。 这是:

// src/Cupon/TiendaBundle/Entity/Tienda.php

namespace Cupon\TiendaBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class Tienda
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;

/** @ORM\Column(type="string", length=100) */
protected $nombre;

/** @ORM\Column(type="string", length=100) */
protected $slug;

/** @ORM\Column(type="string", length=10) */
protected $login;

/** @ORM\Column(type="string", length=255) */
protected $password;

/** @ORM\Column(type="string", length=255) */
protected $salt;

/** @ORM\Column(type="text") */
protected $descripcion;

/** @ORM\Column(type="text") */
protected $direccion;

/** @ORM\ManyToOne(targetEntity="Cupon\CiudadBundle\Entity\Ciudad") */
protected $ciudad;
}

我的意图是使用任务自动生成 getter 和 setter:

G:\xampp\htdocs\cupon>php app/console generate:doctrine:entities TiendaBundle

此任务生成以下错误:

[运行时异常] 找不到“TiendaBundle”的基本路径(路径:“G:\xampp\htdocs\cupon\src\cupon\TiendaBundle”,目的地:G:\xampp\htdocs\cupon\src\cupon\TiendaBundle”)。
doctrine:generate:entities [--path="..."] [--no-backup] 名称

我需要为其他更大的项目自动生成 getter 和 setter。 我希望你的帮助!

【问题讨论】:

  • 您是如何创建该映射的?您可以尝试php app/console doctrine:generate:entity 询问 BundleName 和 (:) 实体名称;然后你会询问字段名称
  • 我没有数据库。我尝试了这个任务 php app/console generate:doctrine:entities TiendaBundle:Tienda 但重新处理了同样的错误。帮忙看看!
  • 好的;如果你去src/Cupon/TiendaBundle文件夹,你会发现有一个名为...Bundle.php的php文件;打开它,让我们知道那个类的名称是什么。其次)确保将 className 添加到 AppKernel.php 的 bundles 数组中
  • 是的,在我的 appKernel.php 中有 new cupon\TiendaBundle\TiendaBundle(), 并且在我的类 TiendaBundle.php 中有 class TiendaBundle extends Bundle { } 和其他东西,例如命名空间等......
  • 解决了。我已经重新安装了框架,但我认为问题是大写和小写的命名空间。区分大小写。 ;)

标签: php symfony doctrine-orm doctrine


【解决方案1】:

通常捆绑名称不仅仅是NameBundle,而是VendorNameBundle。 在您的情况下,它可能是CuponTiendaBundle。 你应该试试:

php app/console generate:doctrine:entities CuponTiendaBundle

如果不起作用,您可以在app/AppKernel.php 的内容中找到您的捆绑包的正确名称。也可以查看G:\xampp\htdocs\cupon\src\cupon\TiendaBundle\*SOMENAME*TiendaBundle.php中的php文件名。

【讨论】:

    【解决方案2】:

    检查 /app/config/parameters.yml 中的数据库连接字符串,如果参数错误可能是原因。

    【讨论】:

    • 这可以添加为评论,一旦有足够的声誉。
    【解决方案3】:

    Getter 和 setter 生成更多的是 IDE 功能(eclipse、phpstorm 和许多其他功能都很好)。

    generate:doctrine:entities 用于从头开始创建实体到数据库中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-05
      • 2010-11-16
      • 1970-01-01
      相关资源
      最近更新 更多