Cześć.
Nie wiem co robię źle ,ale nie umiem sobie poradzić. Staram się podpiąć w Doctrine get i set aby móc pobrać wszystko za jednym id , ale nie wiem co robię źle.
Twig:
{% extends 'master.html.twig' %}
{% block body %}
<div class="col-md-6 col-md-offset-3">
{% for one in take %}
<div class="test">
<p class="float-left">nazwa{{ one.customName }}</p>
<div class="float-left">
<a href="{{ url('auto_createpdf',{'id':one.id}) }}">testuj</a>
</div>
<p>mixture.cas:{{ one.Mixture.cas }}</p>
<p>mixture.name{{ one.Mixture.name }}</p>
<p>copmany.name{{ one.Company.name }}</p>
<p>hp:{{ one.HPhrase.name }}</p>
</div>
{% endfor %}
</div>
{% endblock %}
Controller:
public function autopdfAction()
{
/*$entityManager = $this->getDoctrine()->getManager();
$take = $entityManager->getRepository(CompanyMixture::class)->findAll();*/
$entityManager = $this->getDoctrine()->getManager();
$take = $entityManager -> getRepository(CompanyMixture::class)->findBy(['nr'=>2]);
return $this->render('GeneratorPDF/index.html.twig',['take'=>$take]);
}
klasa: companymixture:
class CompanyMixture
{
/** @var Id */
private $id;
/** @var MsdsFile */
private $msdsFile;
/** @var GenericMixture */
private $genericMixture;
/**
* @var HPhrase
*/
private $hPhrase;
/** @var Company */
private $company;
/**
* @param Id $id
* @param MsdsFile $msdsFile
* @param Mixture $genericMixture
* @param Company $company
* @param HPhrase $hPhrase
* @param null|string $additionalDescription
*/
public function __construct(
Id $id,
?MsdsFile $msdsFile,
GenericMixture $genericMixture,
Company $company,
HPhrase $hPhrase,
?string $additionalDescription = '',
?int $nr = null
) {
$this->id = $id;
$this->msdsFile = $msdsFile;
$this->genericMixture = $genericMixture;
$this->company = $company;
$this->hPhrase = $hPhrase;
$this->additionalDescription = $additionalDescription;
$this->createdAt = new \DateTime();
$this->maxUsage = 0.0;
$company->incrementMixtureCounter();
if ($nr) {
$this->nr = $nr;
} else {
$this->nr = $company->getMixtureCounter();
}
}
/**
* @return HPhrase
*/
public function getHPhrase(): HPhrase
{
return $this->hPhrase;
}
/**
* @param HPhrase $hPhrase
*/
public function setHPhrase(HPhrase $hPhrase)
{
$this->hPhrase = $hPhrase;
}
i klasa HPhrase :
/** @var Collection */
private $companyMixtures;
/**
* @param Id $id
* @param string $name
* @param bool $cmr
* @param CmrType $cmrType
* @param null|string $cmrDescription
* @param OrchCategory $orchCategory
* @param OrchRisk $orchRisk
* @param int $nr
*/
public function __construct(
Id $id,
string $name,
bool $cmr,
?CmrType $cmrType,
?string $cmrDescription,
?OrchCategory $orchCategory,
?OrchRisk $orchRisk,
int $nr = 0
) {
$this->id = $id;
$this->name = $name;
$this->cmr = $cmr;
$this->cmrType = $cmrType->id();
$this->cmrDescription = $cmrDescription;
$this->orchCategory = $orchCategory->id();
$this->orchRisk = $orchRisk->id();
$this->companyMixtures = new ArrayCollection();
$this->nr = $nr;
$this->createdAt = new \DateTime();
}
/**
* @return Collection|ArrayCollection
*/
public function getCompanyMixtures()
{
return $this->companyMixtures;
}
/**
* @param $companyMixture
*/
public function addCompanyMixture($companyMixture)
{
$this->companyMixtures->add($companyMixture);
}
i błąd:
Type error: Return value of Chemiq\Domain\Model\Mixture\CompanyMixture::getHPhrase() must be an instance of Chemiq\Domain\Model\Dictionary\HPhrase, null returned