Search code examples
phptypo3extbasetypo3-6.1.x

TYPO3 Extbase: Access to external data sources (Typo3 "pages" table)


I'm actually writing an extension for an xml export of my pagetree and the content elements. With the following example I've mapped the typo3 "pages" table on my Page model:

# typo3conf/ext/my_publisher/Configuration/TypoScript/setup.txt
# Module configuration
module.tx_mypublisher.persistence.classes {
  Tx_MyPublisher_Domain_Model_Page {
    mapping {
      tableName = pages
      recordType = Tx_MyPublisher_Domain_Model_Page
      columns {
        uid.mapOnProperty =         uid
        pid.mapOnProperty =         pid
        sorting.mapOnProperty =     sorting
        deleted.mapOnProperty =     deleted
        title.mapOnProperty =       title
        is_siteroot.mapOnProperty = is_siteroot
      }
    }
  }
}

Now I want to retrieve the pages in my controller...

$pages = $this->pageRepository->findAll();

This function provides me the result of my model table which is empty until now. So I think I need some "initialize" method in my repository that fills my model table, but until now I've no approach how I can solve this.

Has anyone a solution approach for this problem?

I work with Typo3 6.1.1.

Excuse my English i know it's not the best


Solution

  • First: remove recordType = Tx_MyPublisher_Domain_Model_Page from your mapping, it causes that your repo contains only records which was created as YOUR page, and I assume, that you want to gat any page(s) . Literally, it includes condition to your statement like (depending TCA settings) AND record_type = 'Tx_MyPublisher_Domain_Model_Page'...

    Second: make sure that the storagePid is IGNORED in all your queries, if you'll force some storagePid by TypoScript you'll get only subpages of given page... The easiest way to do that is avoiding storagePid in whole repo, add this method to your PageRepository

    public function initializeObject() {
        $this->defaultQuerySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
        $this->defaultQuerySettings->setRespectStoragePage(FALSE);
    }
    

    Third: Use this tip for checking queries for pages table, it isn't comfortable, however it's the fastest way to find why your repo doesn't get required data (just copy the statement and paste it tou your favorite DB GUI).

    (preferably, paste it to your question, so we will can see what's wrong)

    If there are some questions marks like AND pages.pid = ? in the debugged statement of course you need to replace them with required value AND pages.pid = 123