[TYPO3-mvc] How to send Tx_Extbase_Persistence_ObjectStorage to a Controller action?
Simon Schaufelberger (Schaufi)
simonschaufi at jesus.de
Tue Feb 8 23:34:53 CET 2011
I was digging a bit deeper into the source code of extbase and found
out: it is NOT possible at the moment. ;(
try it yourself in the blog_example:
create an action edit2 in BlogController (add it to ext_localconf.php):
/**
* test function for editing multiple blogs
* @param
Tx_Extbase_Persistence_ObjectStorage<Tx_BlogExample_Domain_Model_Blog> $blog
* @dontvalidate $blog
*/
public function edit2Action(Tx_Extbase_Persistence_ObjectStorage $blog){
print_r($blog);
die('in edit2 Action!');
}
and then call your page like this:
?tx_blogexample_pi1[action]=edit2&tx_blogexample_pi1[controller]=Blog&tx_blogexample_pi1[blog][]=5&tx_blogexample_pi1[blog][]=6
or
?tx_blogexample_pi1[action]=edit2&tx_blogexample_pi1[controller]=Blog&tx_blogexample_pi1[blog][][__identity]=5&tx_blogexample_pi1[blog][][__identity]=6
and what you should get is:
#1231178878: Given property name is not of type string.
It only works if you remove Tx_Extbase_Persistence_ObjectStorage from
the function but then you just get an array and need to map the blogs to
a collection by yourself.
Feature request???
Regards, Schaufi
Am 08.02.2011 11:44, schrieb Franz Koch:
> Hi Simon,
>
>> i have a list of objects and i want to select some with a checkbox to
>> edit those entries in another view.
>>
>> How do I need to format my template and my action so that i can handle
>> that?
>>
>> what i have is the following as a starting point:
>>
>> <f:form method="post" controller="Project" action="edit" name="project">
>> <input type="checkbox" value="1" name="tx_myextension_pi1[projects]">
>> <input type="checkbox" value="2" name="tx_myextension_pi1[projects]">
>> <input type="checkbox" value="3" name="tx_myextension_pi1[projects]">
>> <input type="checkbox" value="4" name="tx_myextension_pi1[projects]">
>> <input type="checkbox" value="5" name="tx_myextension_pi1[projects]">
>> </f:form>
>>
>> <input type="checkbox" value="5" name="tx_myextension_pi1[projects][]">
>>
>> also doesn't help.
>
> Actually I'm not sure if this is going to work, but I never tried it.
> First thing is of course that you have to change the field names to
> reflect a array, otherwise only one of the selected values will be
> submitted. Second thing would be to probably submit the UID as
> __identity, so give the following a try:
>
> <input type="checkbox" value="5"
> name="tx_myextension_pi1[projects][][__identity]">
>
> But as I said - not sure if this is going to work that way. What will
> definitely work would be one of this cases:
>
> - change the argument type to array and fetch the according objects form
> the repository
> - use a little wrapper object as argument type and assign the checkbox
> values to a property of it
>
> /**
> * ...
> */
> public function editAction(Tx_ExtKey_Domain_Model_ProjectDemand
> $projectDemand) {
> $this->view->assign('projects', $projectDemand->getProjects());
> }
>
More information about the TYPO3-project-typo3v4mvc
mailing list