【问题标题】:Get object in i18n form以 i18n 形式获取对象
【发布时间】:2012-04-19 00:09:17
【问题描述】:

在嵌入式 i18n 表单中,我需要获取对象。 在这个例子中,我得到了ArtistImageTranslation 对象,但我需要ArtistImage

谁能帮帮我,怎么弄到这个?

class ArtistImageTranslationForm extends BaseArtistImageTranslationForm
{
  public function configure()
  {
    $this->getObject();
    ....
  }
}

【问题讨论】:

    标签: forms symfony1 internationalization doctrine


    【解决方案1】:

    您是否尝试过以下方法?

    $artistimage = $this->getObject()->getArtistImage();
    

    【讨论】:

    • 我试过并得到了Unknown method ArtistImageTranslation::getArtistImage
    【解决方案2】:

    试试:

    $artistimage = $this->getObject()->artistImage;  
    

    $artistimage = $this->getObject()->artist_image; 
    

    【讨论】:

    • $this->getObject()->artistImage 给出Unknown record property / related component "artistImage" on "ArtistImageTranslation"$this->getObject()->artist_image 给出Unknown record property / related component "artist_image" on "ArtistImageTranslation"
    【解决方案3】:

    我今天在同一个问题上花了半天时间,看来我终于找到了一些东西;)

    首先,如果您需要访问表格“翻译”部分中的字段,您可以直接从表单中包含的对象访问它们。只需在不使用 getter 的情况下访问属性(我知道这不是好方法,但它有效)。所以你可以使用类似的东西:

    $this->getObject()->id;
    $this->getObject()->translated_name;
    

    等等

    如果你真的需要原始对象,你可以这样访问它:

    $this->getObject()->getTable()->getRelation('ArtistImage')
         ->fetchRelatedFor($this->getObject());
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 2014-05-23
      • 1970-01-01
      相关资源
      最近更新 更多