[TYPO3-mvc] Problem with saving a mm relation (frontend)
Kerstin Eitner
eitner.kerstin at googlemail.com
Wed Aug 31 11:55:39 CEST 2011
Hi everybody,
I solved the problem myself.
The important thing is to define the categories in the new-Template as a
multiple field like:
<select id="category" style="width: 15em;" multiple="multiple" size="3"
name="tx_my_list[newEvent][category][]"><option value="1">Konzert</option>
Then everything works fine!
Best regard
Kerstin Eitner
Am 30.08.2011 23:38, schrieb Kerstin Eitner:
> Hi everybody,
>
> I have an event object which can be categorized (birthday, party, wedding).
> If i save a new event with for example two categories in the backend
> everything works fine, the correct db tables are filled and the mm
> relations are created.
>
> But when I try to save the event with categories in a frontend-form,
> extbase goes on with no error but only the event is saved without the
> given categories...
>
> I have compared it with other extbase extension, but i don't get it.
> Can anybody give me a hint what i am doing wrong here?
>
> Thanks in advance,
> Kerstin Eitner
>
>
>
>
> Frontend-Form:
>
> <f:form method="post" action="create" name="newEvent" object="{newEvent}">
> [..]
> <label for="category"><f:translate
> key="tx_my_domain_model_event.category" /></label><br />
> <f:form.select property="category" options="{categories}"
> optionValueField="uid" optionLabelField="title" /><br />
>
> <f:form.submit value="Create new" />
> </f:form>
>
>
>
> Event Model:
>
> /**
> * Categories
> * @var Tx_Extbase_Persistence_ObjectStorage<Tx_My_Domain_Model_Category>
> *
> */
> protected $category;
>
>
> /**
> * Setter for category
> *
> * @param
> Tx_Extbase_Persistence_ObjectStorage<Tx_My_Domain_Model_Category>
> * @return void
> */
> public function setCategory(Tx_Extbase_Persistence_ObjectStorage $cat) {
> $this->category = $cat;
> }
>
>
> TCA Event - Category Field Definition:
>
> 'category' => array(
> 'exclude' => 1,
> 'label' => 'category',
> 'config' => array(
> 'type' => 'select',
> 'foreign_table' => 'tx_my_domain_model_category',
> 'MM' => 'tx_my_event_category_mm',
> 'size' => 10,
> 'autoSizeMax' => 30,
> 'minitems' => 0,
> 'maxitems' => 9999,
> [..]
>
>
> Event-Controller:
>
> /**
> * Initializes the current action
> *
> * @return void
> */
> protected function initializeAction() {
> $this->eventRepository =
> t3lib_div::makeInstance('Tx_My_Domain_Repository_EventRepository');
> }
>
>
> /**
> * Creates a new Event
> *
> * @param Tx_My_Domain_Model_Event $newEvent
> * @return void
> */
> public function createAction(Tx_My_Domain_Model_Event $newEvent) {
> $this->eventRepository->add($newEvent);
> $this->redirect('new');
> }
More information about the TYPO3-project-typo3v4mvc
mailing list