【问题标题】:Mapping to "pages" table from Extbase in TYPO3 6.1从 TYPO3 6.1 中的 Extbase 映射到“页面”表
【发布时间】:2013-07-29 12:13:38
【问题描述】:

我使用域模型 Message 创建了一个扩展。该模型与 TYPO3 pages(具有页面详细信息,如标题、issite_root 等)表的关系为 m:n。但是,通过使用mapping to existing tables 选项,它给了我type 错误提示页面:

The configured type field for table "pages" is of type int(11) unsigned
This means the type field can not be used for defining the record type. 
You have to configure the mappings yourself if you want to map to this
table or extend the correlated class

所以我只创建没有映射的关系,以便以后可以从setup.txt 映射它。

我在MyExt/Classes/Domain/Model/ 中创建了模型Pages,所有的getter/setter 和存储库都在MyExt/Classes/Domain/Repository/ 中。

在我的 setup.txt 中我这样做了:

config.tx_extbase {
    persistence{
        enableAutomaticCacheClearing = 1
        updateReferenceIndex = 0
        classes {
        Tx_Playfield_Domain_Model_Pages {
            mapping {
                    tableName = pages
                columns {
                                uid.mapOnProperty               = uid
                                pid.mapOnProperty               = pid
                                sorting.mapOnProperty           = sorting
                                title.mapOnProperty             = title
                                subtitle.mapOnProperty          = subtitle
                            }
                }
            }
      }
    }
}

但是当我尝试访问我创建的 Pages 模型时,

var_dump($this->pagesRepository->findByUid(74));

它搜索不存在的tx_playfield_domain_model_pages,它显示

Table 'typo3.tx_playfield_domain_model_pages' doesn't exist: SELECT tx_playfield_domain_model_pages.* FROM tx_playfield_domain_model_pages WHERE tx_playfield_domain_model_pages.uid = '74' LIMIT 1

我在这里错过了什么?

更新

在关注@Michael 建议的http://t3-developer.com/extbase-fluid/cheats-extbase/model/tabelle-pages-in-extbase/ 后,我从$this->pagesRepository->findByUid(74) 得到empty result

setup.txt 正在加载。我这样做是为了检查它:

plugin.tx_playfield{
settings{
 temp=yes
}
}

这是从我的控制器访问的。

【问题讨论】:

  • setup.txt 对我来说看起来不错。您的模型在 MyExt/Classes/Domain/Model/Pages.php 中是如何定义的?您是否检查过 setup.txt 是否在运行时实际加载(使用 TS 对象浏览器stackoverflow.com/a/6671818/283854)?您是否尝试使用 config.tx_playfield 而不是 config.tx_extbase 设置相同的内容?
  • 是的。我更新了,似乎 setup.txt 已加载,但是 extbase 不知道它的映射。我也试过config.tx_playfield,但它不起作用!
  • 顺便说一句:最好使用\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($var, 'Name'); 进行调试。它有很多优点。
  • 在扩展 pw_teaser (source code) 中有一个页面/tt_content 的有效 Extbase 实现。

标签: typo3 extbase


【解决方案1】:

您是否可能没有创建 Pages 域模型(在扩展构建器中或根本没有)?文件my_ext/Classes/Domain/Model/Pages.php 需要存在。检查您的“页面”域模型是否将属性映射到现有表设置为页面,它应该如下所示:

我不知道您的错误到底出在哪里,但我在扩展构建器中做了一些修改并使其正常工作。您可能可以通过将您的扩展 playfield 与我的临时扩展 testfield 进行比较来找出答案:Download it here (updated)


顺便说一句,您不需要映射不希望在前端显示的属性,除非它们的名称不同。

        mapping {
            tableName = pages
            columns {
                title.mapOnProperty = title
                subtitle.mapOnProperty = subtitle
            }
        }

【讨论】:

  • 是的。我最初确实从扩展生成器中添加了Pages,但由于显示出奇怪的错误,我自己创建了一个。但是,您的扩展 testfield 正是我想要的。非常感谢:)
  • 我最初没有从扩展生成器映射它,这是错误。但现在我做到了,并以 stackoverflow.com/questions/17962619/… 作为参考能够使其工作
【解决方案2】:

我认为你必须用驼峰字母(类名)编写映射。尽管this post 是德语,但我认为代码可能会对您有所帮助。作者在类中添加了一些他将要使用的字段,并在扩展的打字稿中添加了一个映射(参见那里的示例代码)。德语文本中最重要的部分是该示例仅设计为从 db 读取。如果您想使用模型创建新页面,您必须(至少)在模型类中添加 TCA 和设置器以使其工作。

【讨论】:

  • 感谢您的资源。我也是这么做的。现在它只是在我做$this->pageRepository->findAll()->toArray()时向我显示empty result
  • Extbase 似乎不知道映射并因此显示NULL 结果
猜你喜欢
  • 2013-08-26
  • 1970-01-01
  • 2013-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-04
  • 1970-01-01
  • 2014-01-25
相关资源
最近更新 更多