I have upgraded my project from TYPO3 7.6
to TYPO3 8.7
. The UID variable {singleMember.uid}
is being fetched the database and displayed. But when I want to fetch {singleMember.name}
or {singleMember.email}
, it is always empty, even though the 'name' and 'email' columns are present in the database table.
Controller/MemberController.php
public function listBeAction() {
$members = $this->memberRepository->findAllSorted(array($sortField => $sortDir ));
$members = $this->memberRepository->findAll();
$this->view->assign('members', $members);
}
Domain/Repository/MemberRepository.php
public function findAllSorted($sorting = NULL) {
$query = $this->createQuery();
$query->setOrderings($sorting);
return $query->execute();
}
Domain/Model/Member.php
class Member extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
protected $name;
protected $email;
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getEmail() {
return $this->email;
}
public function setEmail($email) {
$this->email = $email;
}
}
Does anybody know where I went wrong?
First, one of the following line of your code is superfluous in your controller, because the second one overwrites the result of the first one:
$members = $this->memberRepository->findAllSorted(array($sortField => $sortDir ));
$members = $this->memberRepository->findAll();
The second issue is that you might have forgotten just a headline in your question, or you placed a function in the controller instead of the repository, this belongs at least in the repository:
public function findAllSorted($sorting = NULL) {
$query = $this->createQuery();
$query->setOrderings($sorting);
return $query->execute();
}
The model class still has two issues too:
the namespace might be missing, it's the 2nd line in the file usually and looking like this:
namespace Vendor\\ExtensionName\\Domain\\Model;
, where Vendor
and ExtensionName
have to be replaced by your own values.
Annotations are missing, they are used to validate the fields even they are notated as php-comments.
So all together your model file has to look like this:
<?php
namespace Vendor\ExtensionName\Domain\Model; // replace 'vendor' and 'ExtensionName' by your own values
class Member extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* name
*
* @var string
*/
protected $name;
/**
* email
*
* @var string
* @validate EmailAddress
*
* @see \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
* @see https://docs.typo3.org/typo3cms/extensions/configuration_object/04-Administration/Validators/Index.html
* @important never accepts umlauts in the complete email-address, validate it individually to allow those addresses!
*/
protected $email;
/**
* Returns the name
*
* @return string $name
*/
public function getName()
{
return $this->name;
}
/**
* Sets the name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Returns the email
*
* @return string $email
*/
public function getEmail()
{
return $this->email;
}
/**
* Sets the email
*
* @param string $email
*/
public function setEmail($email)
{
$this->email= $email;
}
}
To your question:
The reasons are quite unclear why the objects never return the desired values, also because you never provided the code of the whole extension.
Here are thinkable reasons:
findAll()
and/or findAllSorted
in the repository class are coded to return only the uid of each record. This case is very unlikely but I just mention it. ext_tables.sql
and Configuration/TCA/tx_yourextension_domain_model_member.php
(replace tx_ yourextension _... by your value). Further reasons might be thinkable, but perhaps you check first the points I mentioned and give feedback. If required you can give more information and I can extend my answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.