[TYPO3-mvc] Putting together a object for updateAction, from ExtJs/json

Dmitri Pisarev dimaip at gmail.com
Wed Mar 17 08:06:21 CET 2010


Hi!
I'm a complete novice at extbase, but the way you do it looks really 
strange to me.
Why not do this like this:
	/**
	 * Updates client.
	 *
	 * @param Tx_Alex_Domain_Model_Client $client
	 * @return string The rendered view
	 * @dontverifyrequesthash
	 */
	public function updateAction($client) {
		$this->clientRepository->update($client);
		$this->flashMessages->add('Your client was updated.');
		echo '{success:true}';
	}	
And from extjs submit something like this:
tx_alex_pi1[__referer][ac...	index
tx_alex_pi1[__referer][co...	Client
tx_alex_pi1[__referer][ex...	Alex
tx_alex_pi1[client][__identity]	1
tx_alex_pi1[client][addre...	Leninsky
tx_alex_pi1[client][telep...	3395701
tx_alex_pi1[client][title...	Nord-Way
Sorry, firebug has croped the names, but you get the idea.

Regards,
Dmitri.
On 15.03.2010 22:18, dennis ahrens wrote:
> Hi Søren,
>
> I've solved the problem like shown in the following action:
>
> 	/**
> 	 * Updates a record
> 	 *
> 	 * TODO: make the extjs Store to use the extbase controller parameter
> signature, that we
> 	 * can fetch the data out of $this->request->getArgument('data');
> 	 *
> 	 * @return void
> 	 */
> 	public function updateAction() {
> 		try {
> 				// read and prepare data from POST
> 			$dataJson = t3lib_div::_POST('data');
> 			$dataArray = json_decode($dataJson,true);
> 			$uid = (int) t3lib_div::_POST('uid');
> 				// fetch the projekt that should be updated
> 			$forschungsprojekt = $this->forschungsprojektRepository->findByUid($uid);
> 				// apply the changes to the object
> 			$forschungsprojekt = $this->applyUpdate($dataArray,$forschungsprojekt);
> 				// apply the changes to the database
> 			$this->forschungsprojektRepository->update($forschungsprojekt);
> 				// sync group configuration for access management
> 			$this->accessManager->write($forschungsprojekt);
> 				// tell the view layer that everything is ok
> 			$this->view->assign('changedData',$dataArray);
> 			$this->view->assign('success',TRUE);
> 			$this->view->assign('message', '');
> 		} catch (Exception $e) {
> 			if (!is_array($dataArray))
> 				$dataArray = array();
> 				// tell the view layer that something is not ok ... :)
> 			$this->view->assign('changedData',$dataArray);
> 			$this->view->assign('success',FALSE);
> 			$this->view->assign('message','Forschungsprojekt konnte nicht
> gespeichert werden');
> 				// tell the developer a little bit about the occured error
> 			t3lib_div::sysLog('Exception: ' .
> $e->getMessage(),'FhhForschungsprojekte',4);
> 			t3lib_div::sysLog('Exception-Trace: ' .
> $e->getTraceAsString(),'FhhForschungsprojekte',3);
> 		}
> 	}
>
> The "mapping" between the json data and the model is hidden behind
> applyUpdate().
> I use the extjs jsonwriter config option 'writeAllFields' for just
> telling the server about the made changes.
>
> I think it would be much better to do the mapping when intializing the
> action argument - but haven't found the time yet to dig deeper
> there...
>
> regards
> Dennis
>
> 2010/3/15 Søren Malling<soren.malling at gmail.com>:
>> Hi,
>>
>> Getting closer to the goal of my first Extbase and ExtJs project I've
>> ran into a issue.
>>
>> When posting to my Extbase page, where the update-, index-,
>> createAction etc are placed, the data is posted as POST. The update
>> action requires a object of Tx_Groupmembers_Domain_Model_Member
>>
>> public function updateAction(Tx_Groupmembers_Domain_Model_Member $member) {
>>
>> but how do i create a object mathcing the "shape" of a Domain_Model
>> object? Is it possible/correc to remove the
>> "Tx_Groupmembers_Domain_Model_Member $member" part of the function and
>> then create the a object based on the "POST" data or should i look in
>> to ExtJs to see how I can submit it like a object in someway?
>>
>> Regards,
>>
>> Søren
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>



More information about the TYPO3-project-typo3v4mvc mailing list