jjzjj

php - Symfony 2,MongoDB + a2lix/translation-form-b​​undle

coder 2023-11-01 原文

我在 Symfony 2.5 中使用 MongoDB 时遇到包“a2lix/translation-form-b​​undle”的问题。我想我已经按照文档中的说明完成了所有操作,但是我有“缺少必需的选项“class”。”错误。

我的产品:

/**
 * Class Product
 * @MongoDB\Document(repositoryClass="MyBundle\ProductBundle\Repository\ProductRepository")
 * @Gedmo\TranslationEntity(class="MyBundle\ProductBundle\Document\ProductTranslation")
 */
class Product implements Translatable
{

/**
 * @MongoDB\Id
 *
 */
protected $id;

/**
 * @MongoDB\String
 * @Gedmo\Translatable
 */
protected $name;

/**
 *
 * @MongoDB\ReferenceMany(targetDocument="MyBundle\ProductBundle\Document \ProductTranslation", mappedBy="object", cascade={"all"})
 *
 */
private $translations;


public function __construct()
{
    $this->translations = new ArrayCollection();
}

public function __toString()
{
    return $this->getName();
}

/**
 * Get id
 *
 * @return id $id
 */
public function getId()
{
    return $this->id;
}

/**
 * Set name
 *
 * @param string $name
 * @return self
 */
public function setName($name)
{
    $this->name = $name;
    return $this;
}

/**
 * Get name
 *
 * @return string $name
 */
public function getName()
{
    return $this->name;
}

/**
 * Set translations
 *
 * @param ArrayCollection $translations
 * @return Product
 */
public function setTranslations($translations)
{
    foreach ($translations as $translation) {
        $translation->setObject($this);
    }

    $this->translations = $translations;
    return $this;
}

/**
 * Get translations
 *
 * @return ArrayCollection
 */
public function getTranslations()
{
    return $this->translations;
}

这是我的产品翻译:

class ProductTranslation extends AbstractPersonalTranslation
{
/**
 * @MongoDB\ReferenceOne(targetDocument="MyBundle\ProductBundle\Document\Product", inversedBy="translations")
 *
 */
public $object;

}

我仍然收到“缺少必需的选项“类”。”错误,我不知道是什么问题。

最佳答案

您收到此错误是因为 MongoDB ODM 映射在引用上创建了一个字段映射。

例如,当您有 ManyToOne 或 OneToMany 关系时,ORM 不会创建字段映射。

因此 a2lix 将您的 object 字段视为通常的映射字段。由于表单生成器解析此 object 字段,如 document 类型,因此您需要提供 class 选项以使其工作。

但是,如果您提供此选项,那么您的 object 字段将呈现为可翻译字段,这绝对很糟糕。

所以请试试这个:

->add('translations', 'a2lix_translations', [
    'exclude_fields' => [
        'object',
    ]
])

它将帮助您解决这个特定问题。

关于php - Symfony 2,MongoDB + a2lix/translation-form-b​​undle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31136722/

有关php - Symfony 2,MongoDB + a2lix/translation-form-b​​undle的更多相关文章

  1. ruby-on-rails - Rails 3 I18 : translation missing: da. datetime.distance_in_words.about_x_hours - 2

    我看到这个错误:translationmissing:da.datetime.distance_in_words.about_x_hours我的语言环境文件:http://pastie.org/2944890我的看法:我已将其添加到我的application.rb中:config.i18n.load_path+=Dir[Rails.root.join('my','locales','*.{rb,yml}').to_s]config.i18n.default_locale=:da如果我删除I18配置,帮助程序会处理英语。更新:我在config/enviorments/devolpment

  2. ruby-on-rails - 运行 Heckle 时出错? `current_code' : undefined method `translate' for Ruby2Ruby - 2

    我正在尝试运行Heckle,但一直出现错误:>specspec/controllers/my_controller_spec.rb--heckleMyController!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!exception=hasathickskin.There'snothingtoheckle.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(Runsthroughseveralmu

  3. ruby-on-rails - Rails 国际化 : %{record} is not being translated - 2

    我的rails.pt-BR.yml上有这个:br:errors:format:!'%{attribute}%{message}'messages:restrict_dependent_destroy:one:"Nãoépossívelexcluiroregistropoisexisteum%{record}dependente"many:"Nãoépossívelexcluiroregistropoisexistem%{record}dependentes"在我的模型中,我有这个:has_many:entities,dependent::restrict_with_error每当res

  4. ruby - 通过 node-sass 的 Symfony assetic sass 过滤器? - 2

    我在让asseticsass过滤器与node-sass而不是ruby​​替代品一起工作时遇到了一些困难。我的config.yml文件中有以下配置:assetic:debug:"%kernel.debug%"use_controller:falsebundles:[]write-to:"%kernel.root_dir%/../web/assets"read_from:"%kernel.root_dir%/../web/assets"node:"%%PROGRAMFILES%%\nodejs\\node.exe"node_paths:["%%USERPROFILE%%\\AppData\

  5. ruby-on-rails - 在一个 Rails 应用程序中使用 PostgreSQL 的 MongoDB - 2

    我可以在一个Rails应用程序中同时使用MongoDB和PostgreSQL吗?具体来说,我最终会想要使用像MongoHQ这样的东西。到目前为止,我未能在实验中进行这项工作。令我担心的是,MongoDB文档特别指出我必须禁用ActiveRecord。任何建议将不胜感激。 最佳答案 您无需禁用ActiveRecord即可使用MongoDB。查看Mongoid只需将gem加上任何模型与您现有的任何ActiveRecord模型一起添加。您应该注意到MongoHQ只是MongoDB的托管服务,可以与任何对象文档映射器(ODM)一起使用。更多

  6. ruby - 使用 mongodb/mongoid 运行时更改模型 - 2

    我必须在mongoid模型中添加几个字段,我知道MongoDB没有迁移,但如果我继续而不删除数据库,使rails完全“重新生成”数据库,它不会显示或使用新的领域!去这里最好的方法是什么?有比删除/重新打开mongodb更软的东西吗?提前致谢卢卡 最佳答案 一般来说,应该可以在运行时用新字段更新旧文档。MongoDB中不需要迁移。您可能想编写rake任务以使用新字段和默认值更新旧文档。您可以通过检查那些默认值为nil的新字段来找到这些文档。更新简单风格:如果您使用默认值定义一个新字段,只要您设置了一个新值,就应该始终使用该值:应用程序

  7. ruby-on-rails - 我如何从 Ruby 代码连接到 mongodb? - 2

    我如何从Ruby代码连接到mongodb? 最佳答案 首先,您必须安装MongoDbgem:geminstallmongo然后运行代码:require'rubygems'#notnecessaryforRuby1.9require'mongo'db=Mongo::Connection.new.db("mydb")#ORdb=Mongo::Connection.new("localhost").db("mydb")#ORdb=Mongo::Connection.new("localhost",27017).db("mydb")

  8. ruby - MongoDB:无法从 BSON 类型 EOO 转换为 Date - 2

    我正在尝试使用聚合框架(使用ruby​​)并像这样投影日期:db['requests'].aggregate([{"$project"=>{_id:0,method:'$method',user:'$user',year:{'$year'=>'$timestamp'}}}])文档是这样的:{_id:ObjectId("5177d7d7df26358289da7dfd"),timestamp:ISODate("2013-04-12T03:58:05+00:00"),method:"POST",status:"200",inputsize:"874",outputsize:"4981",u

  9. ruby - 在 Ruby 中从 MongoDB 中检索字段的子集 - 2

    我试图通过在Ruby中进行的查询从MongoDB获取字段的子集,但它似乎不起作用。它不返回任何结果这是ruby代码:coll.find("title"=>'Halo',:fields=>["title","isrc"])#thisdoesn'twork如果我删除字段散列,它会工作,返回包含所有字段的结果coll.find("title"=>'Halo')#thisworks查看mongodb控制台,第一个查询在mongodb服务器上结束,如下所示:{title:"Halo",fields:["title","isrc"]}如果我尝试从mongo客户端控制台进行查询,它会工作,我会得到结

  10. ruby-on-rails - I18n : How to check if a translation key/value pairs is missing? - 2

    我正在使用RubyonRails3.1.0和I18ngem.我(正在实现一个插件)我想在运行时检查I18n是否缺少翻译键/值对,如果是,则使用自定义字符串。也就是说,我有:validates:link_url,:format=>{:with=>REGEX,:message=>I18n.t('custom_invalid_format',:scope=>'activerecord.errors.messages')}如果.yml文件中没有如下代码activerecord:errors:messages:custom_invalid_format:Thisisthetesterrormes

随机推荐