Hallo miteinander,
Hoffe das Thema/Problem wurde noch nicht durchgekaut, hab hier nichts gefunden,
das mir dabei geholfen hat.
Bin Extbase Einsteiger und möchte eine Extension erstellen,
die tt_address Datensätze ausgibt und über ein select input
nach Gruppen filtert.
Die Ausgabe der Datensätze aus der tt_address Tabelle erfolgt auch ohne Probleme,
nur das mit den Gruppen (n:m Relation) funktioniert nicht ganz
bzw. ist mir nicht ganz verständlich.
folgendes habe ich bis jetzt gemacht:
Weil tt_address eine m:m Relation benutzt hab ich im Extension Builder erstmal
wie im Anhang auf extension_builder.jpg zu sehen zwei Modelle angelegt mit einer
m:n Relation.
Daraufhin wurden auch passen zwei Tabellen mit einer Zwischentabelle angelegt.
Soweit so gut. In meiner Model Addresses.php hat mir der Builder nun freundlicherweise
folgenden Programmblock für die Addressgruppen generiert:
/**
* the address groups
*
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_Wuwwaddress_Domain_Model_Groups>
*/
protected $addressgroup;
/**
* __construct
*
* @return void
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all Tx_Extbase_Persistence_ObjectStorage properties.
*
* @return void
*/
protected function initStorageObjects() {
/**
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*/
$this->addressgroup = new Tx_Extbase_Persistence_ObjectStorage();
}
/**
* Adds a Groups
*
* @param Tx_Wuwwaddress_Domain_Model_Groups $addressgroup
* @return void
*/
public function addAddressgroup(Tx_Wuwwaddress_Domain_Model_Groups $addressgroup) {
$this->addressgroup->attach($addressgroup);
}
/**
* Removes a Groups
*
* @param Tx_Wuwwaddress_Domain_Model_Groups $addressgroupToRemove The Groups to be removed
* @return void
*/
public function removeAddressgroup(Tx_Wuwwaddress_Domain_Model_Groups $addressgroupToRemove) {
$this->addressgroup->detach($addressgroupToRemove);
}
/**
* Returns the addressgroup
*
* @return Tx_Extbase_Persistence_ObjectStorage<Tx_Wuwwaddress_Domain_Model_Groups> $addressgroup
*/
public function getAddressgroup() {
return $this->addressgroup;
}
/**
* Sets the addressgroup
*
* @param Tx_Extbase_Persistence_ObjectStorage<Tx_Wuwwaddress_Domain_Model_Groups> $addressgroup
* @return void
*/
public function setAddressgroup(Tx_Extbase_Persistence_ObjectStorage $addressgroup) {
$this->addressgroup = $addressgroup;
}
Soweit mal alles in Ordnung.
Da ich ja nun keine extensioneigenen Datensätze benutze hab ich das ganze im setup.txt wie folgt gemappt:
plugin.tx_wuwwaddress {
view {
templateRootPath = {$plugin.tx_wuwwaddress.view.templateRootPath}
partialRootPath = {$plugin.tx_wuwwaddress.view.partialRootPath}
layoutRootPath = {$plugin.tx_wuwwaddress.view.layoutRootPath}
}
persistence {
storagePid = 23
classes {
Tx_Wuwwaddress_Domain_Model_Addresses {
mapping {
tableName = tt_address
recordType = Tx_Wuwwaddress_Domain_Model_Addresses
columns {
first_name.mapOnProperty = firstname
last_name.mapOnProperty = lastname
company.mapOnProperty = company
address.mapOnProperty = street
zip.mapOnProperty = zip
country.mapOnProperty = country
fax.mapOnProperty = fax
phone.mapOnProperty = phone
uid.mapOnProperty = email
www.mapOnProperty = homepage
}
}
subclasses{
Tx_Wuwwaddress_Domain_Model_Groups = Tx_Wuwwaddress_Domain_Model_Groups
}
}
Tx_Wuwwaddress_Domain_Model_Groups{
mapping{
tableName = tt_address_group
recordType = Tx_Wuwwaddress_Domain_Model_Groups
columns{
uid.mapOnProperty = gid
title.mapOnProperty = gruppe
}
}
}
}
}
...und wo weiter
Als nächstes habe ich nach diesem Schema meine Properties festgelegt:
/**
* company
*
* @var \string
* @validate NotEmpty
*/
protected $company;
/**
* Returns the company
*
* @return \string $company
*/
public function getCompany() {
return $this->company;
}
und die vorher generierten funtionen wie set, remove etc. für die Addressgruppen entfernt da ich ja nur get brauche um sie auszugeben.
Im Controller wurde folgendes generiert:
*/
class Tx_Wuwwaddress_Controller_AddressesController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* addressesRepository
*
* @var Tx_Wuwwaddress_Domain_Repository_AddressesRepository
*/
protected $addressesRepository;
/**
* injectAddressesRepository
*
* @param Tx_Wuwwaddress_Domain_Repository_AddressesRepository $addressesRepository
* @return void
*/
public function injectAddressesRepository(Tx_Wuwwaddress_Domain_Repository_AddressesRepository $addressesRepository) {
$this->addressesRepository = $addressesRepository;
}
/**
* action list
*
* @return void
*/
public function listAction() {
$addressess = $this->addressesRepository->findAll();
$this->view->assign('addressess', $addressess);
}
/**
* action search
*
* @return void
*/
public function searchAction() {
}
}
Und zu guter letzt noch das template das wie folgt aussieht:
<f:layout name="Default" />
This Template is responsible for creating a table of domain objects.
If you modify this template, do not forget to change the overwrite settings
in /Configuration/ExtensionBuilder/settings.yaml:
Resources:
Private:
Templates:
List.html: keep
Otherwise your changes will be overwritten the next time you save the extension in the extension builder
<f:section name="main">
<h1>Listing for Addresses</h1>
<f:flashMessages />
<f:for each="{addressess}" as="addresses">
<f:debug>{addresses}</f:debug>
<h4>
{addresses.company}
</h4>
<table>
<tr>
<td>
Straße:
</td>
<td>
{addresses.address}
</td>
</tr>
<tr>
<td>
Postleitzahl:
</td>
<td>
{addresses.zip}
</td>
</tr>
<tr>
<td>
Stadt:
</td>
<td>
{addresses.city}
</td>
</tr>
<tr>
<td>
Land:
</td>
<td>
{addresses.country}
</td>
</tr>
<tr>
<td>
Telefon:
</td>
<td>
{addresses.phone}
</td>
</tr>
<tr>
<td>
Fax:
</td>
<td>
{addresses.fax}
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
{addresses.email}
</td>
</tr>
<tr>
<td>
WWW:
</td>
<td>
{addresses.homepage}
</td>
</tr>
</table>
<hr />
</f:for>
</f:section>
Was jetzt dabei rauskommt ist im Anhang auf fe_ausgabe.jpg zu sehen.
die Daten aus der tt_address tabelle werden schon mal ausgegeben.
Wenn ich jetzt aber ein select feld anlegen würde wüsste ich nicht wie
ich die gruppen ausgeben soll also mit welcher Variable o.ä.
Wie man im debugger sehen kann, sind die daten der gruppen wieder als ganzes array im array vorhanden.
Und der titel der gruppe den ich gemappt habe, der ist garnicht vorhanden.
jetzt zu meinen fragen:
1.Wie kann ich die Daten aus dem objectStorage richtig ausgeben? Mit {addresses.addressgroup}
oder so ähnlich geht das ja nicht(Das es einen ViewHelper fürs selectfeld gibt weiß ich). Kann mit dem objectStorage nicht so richtig was anfangen.
2.Ist das richtig dass ich die klasse der gruppe im setup als subclass genommen habe?
...oder läuft grundsätzlich was falsch?
Bin für alle Hinweise dankbar.
Danke schon mal im Vorraus
Gruß

