Repository for existing Extbase model class
If you want to use an existing extbase model like Category but want to create a custom repository to implement some custom queries, here is the way to go:
Create typo3conf/ext/your_ext/Classes/Domain/Model/Category.php:
<?php
namespace Dummy\YourExt\Domain\Model;
/**
* Category
*/
class Category extends \TYPO3\CMS\Extbase\Domain\Model\Category {
}
Create typo3conf/ext/your_ext/Classes/Domain/Repository/CategoryRepository.php:
<?php
namespace Dummy\YourExt\Domain\Repository;
/**
* The repository for Categories
*/
class CategoryRepository extends \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository {
// some custom query methods here
}
Create typo3conf/ext/your_ext/ext_typoscript_setup.txt:
config.tx_extbase{
persistence{
classes{
Dummy\YourExt\Domain\Model\Category {
mapping {
tableName = sys_category
recordType = Tx_YourExt_Category
}
}
}
}
}
Clear the cache and you're ready to go!