[TYPO3-mvc] Chance to "map" TableNames
Xavier Perseguers
typo3 at perseguers.ch
Tue Jul 21 10:56:59 CEST 2009
Hi,
>>> In case the tables are not in TYPO3, you can also do the object
>>> relational mapping on your own, and just pass the objects to Fluid.
>>>
>>> If you do that, I think you need to fix some more stuff, but in
>>> general this should work.
>>
>> I confirm. I do this with a SQL Server database with rvt_adodb and
>> DBAL (a mix of them for the moment) to connect to it and I created my
>> own repository and object model. Then it is integrated in Fluid
>> without further adjustment.
>>
> may you post your repository as example. im Currently stuck...
> YOu just implemented an repo which implements the repo interface, doing
> your own queries to another db? did i get it?
I started before Extbase even existed and then moved to part of Extbase
(but I did not change the integration recently as of new features of
Extbase regarding those use cases as I did not have time to investigate
more for the moment whether I could still simplify).
Basically I did this:
.
|-- Classes
| `-- Domain
| `-- Model
| |-- AbstractEntity.php
| |-- AbstractRepository.php
| |-- Person.php
| `-- PersonRepository.php
`-- Persistence
`-- DataAccess.php
Content of my files:
AbstractEntity.php
--------------------------------
abstract class Tx_MyExt_Domain_Model_AbstractEntity extends
Tx_Extbase_DomainObject_AbstractDomainObject
content is a copy of Tx_Extbase_DomainObject_AbstractEntity (methods
_memorizeCleanState, _getDirtyProperties, _isDirty) without dependency
on Tx_Extbase_Persistence_Mapper_ObjectRelationMapper. This has changed
for sure but I did not check recently
AbstractRepository.php
--------------------------------
abstract class Tx_MyExt_Domain_Model_AbstractRepository extends
Tx_Extbase_Persistence_Repository {
protected $dao;
public function __construct() {
parent::__construct();
$this->dao =
t3lib_div::makeInstance('Tx_MyExt_Persistence_DataAccess');
}
}
Person.php
--------------------------------
class Tx_MyExt_Domain_Model_Person extends
Tx_MyExt_Domain_Model_AbstractEntity
the rest is as for standard entities in Extbase
PersonRepository.php
--------------------------------
class Tx_MyExt_Domain_Model_PersonRepository extends
Tx_MyExt_Domain_Model_AbstractRepository
contains methods findBy... which call $this->dao->findPersonBy... and
reconstruct the Person objects using ->_setProperty() calls and call
_memorizeCleanState at the end.
DataAccess.php
--------------------------------
Tx_MyExt_Persistence_DataAccess implements t3lib_Singleton
this holds a connection to the database (in protected $db) using
EXT:rvt_adodb (you may use DBAL and $GLOBALS['TYPO3_DB'] instead)
and contains methods find<class>By...($params), perform the query and
returns a array of result. O/R Mapping is done in my repositories. This
has less layers than in Extbase but is quite easy to do.
Next step will be to integrate even more with Extbase but I need time...
--
Xavier Perseguers
DBAL-Member
http://xavier.perseguers.ch/en/tutorials/typo3.html
More information about the TYPO3-project-typo3v4mvc
mailing list