Mapping to “pages” table from Extbase in TYPO3 6.1

被刻印的时光 ゝ 提交于 2019-12-30 19:17:31

问题


I created an extension with a domain model Message. This model has a relation m:n with the TYPO3 pages (the one which has the details of the pages, like title, issite_root etc) table. However, by using the mapping to existing tables option, it gives me type error saying page :

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

So I just create the relation without mapping, so that I can later map it from setup.txt.

The I created model Pages in MyExt/Classes/Domain/Model/ with all the getters/setters and repository in MyExt/Classes/Domain/Repository/.

In my setup.txt I did this:

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
                            }
                }
            }
      }
    }
}

But when I try to access the Pages model I created,

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

its searching for tx_playfield_domain_model_pages which does not exists, it shows

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

What am I missing here?

Update

After following http://t3-developer.com/extbase-fluid/cheats-extbase/model/tabelle-pages-in-extbase/ suggested by @Michael I get an empty result from $this->pagesRepository->findByUid(74)

setup.txt is loading. I did this to check it:

plugin.tx_playfield{
settings{
 temp=yes
}
}

And this is being accessed from my controller.


回答1:


Is it possible that you didn't create the Pages domain model (within the extension builder or not at all)? The file my_ext/Classes/Domain/Model/Pages.php needs to exist. Check that your "Pages" domain model has the property Map to existing table set to pages, it should look like that:

I don't know where exactly your error is, but I did some more tinkering in the extension builder and made it work. You can probably find out by comparing your extension playfield to my temporary extension testfield: Download it here (updated).


Btw, you don't need to map properties that you do not want to be displayed in the frontend unless they are named differently.

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



回答2:


I think you have to write the mapping with camel case letters (the class name). Although this post is in German, I think the code might help you. The author added some fields he is going to use to the class and also added a mapping in the typoscript of the extension (see the example code there). The most important part of the German text is that this example there was designed only to read from the db. If you want to create new pages using the model, you have (at least) to add the TCA and setters in the model class to make it work.



来源:https://stackoverflow.com/questions/17928551/mapping-to-pages-table-from-extbase-in-typo3-6-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!