[TYPO3-english] Repositories retunrs only uid after clear caches

Jigal van Hemert jigal.van.hemert at typo3.org
Mon Sep 12 22:20:49 CEST 2016


Hi,

On 09/09/2016 21:49, Alexandra Constantin wrote:
> I have created a new extension with extbase and fluid.
> My contoller looks like:
>
> class Tx_elodevtrainings_Controller_TrainingController extends
> Tx_Extbase_MVC_Controller_ActionController {
>
>     /**
>      * @var Tx_elodevtrainings_Domain_Repository_TrainingOfferRepository
>      * @inject
>      */
>     protected $trainingOfferRepository;
>
>     /**
>      * @param
> Tx_elodevtrainings_Domain_Repository_TrainingOfferRepository
> $trainingOfferRepository
>      */
>     public function
> injectReferenceRepository(Tx_elodevtrainings_Domain_Repository_TrainingOfferRepository

You have both @inject and an inject function; that's one too many. The 
inject function is slightly faster so best practise is to drop the @inject

> $trainingOfferRepository) {
>         $this->trainingOfferRepository = $trainingOfferRepository;
>     }
>
>     public function trainingTestingAction() {
>         //var_dump($this->settings['foo']);
>         $trainingOffers =
> $this->trainingOfferRepository->getAll()->toArray();

->findAll() is available by default and returns all (visible) records.
toArray() is not needed; in Fluid you can iterate over a query result. 
If you're going to use a paginate widget it's even better to use a query 
result as the paginate widget will modify the query with a start and 
limit before it's executed.

>         var_dump($trainingOffers[0]->getTitle());
>         $this->view->assign('trainingOffers', $trainingOffers);
>     }
>
> }
>
> My repository looks like:
>
> class Tx_elodevtrainings_Domain_Repository_TrainingOfferRepository
> extends Tx_Extbase_Persistence_Repository
> {
>
>    public function getAll(){
>        $query = $this->createQuery();
>        $statement = 'SELECT * FROM
> tx_mkelopartner_trainingfinder_trainingoffers WHERE deleted = 0 AND
> hidden = 0';
>        $query->statement($statement);
>        return $query->execute();
>    }

You don't need this. findAll() is always available and returns all 
(visible) records.
With an empty repository class you can already use:
- findAll
- findBy<property>
- findOneBy<property>

Also, only use a raw query if there is no other solution.

> }
>
> My typoscript looks like:
>
> plugin.tx_elodevtrainings.persistence.storagePid.data = page:uid
> plugin.tx_elodevtrainings.persistence.storagePid = page:uid

Why this second line? It'll only set storagePid to the string "page:uid"...

>
> page.includeJS{
>    test = EXT:elodevtrainings/Resources/Public/test.js
> }
>
>
> plugin.tx_elodevtrainings {
>    persistence {
>        storagePid.data = page:uid
>        classes {
>            Tx_elodevtrainings_Domain_Model_TrainingOffer {
>                mapping {
>                    tableName =
> tx_mkelopartner_trainingfinder_trainingoffers
>                    columns{
>                        title.mapOnProperty = title
>                    }
>                }
>            }
>        }
>    }
>
> }
>
> The problem that I have is:  after clear all caches from BE the title
> and all the properties of tx_mkelopartner_trainingfinder_trainingoffers
> are null and it returns only uid.
> It looks like it dosen't read typoscript setup after clear all caches.

Why do you think that? The mapping to the table seems to work. The 
column mapping is not necessary because both column names are the same.

-- 
Jigal van Hemert
TYPO3 CMS Active Contributor

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the TYPO3-english mailing list