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

Søren Malling soren.malling at gmail.com
Tue Mar 16 14:11:30 CET 2010


Thanks a ton, Dennis! :-)

I'll try to build that in in this week, thanks again!

Søren

On Mon, Mar 15, 2010 at 8:18 PM, dennis ahrens
<dennis.ahrens at googlemail.com> 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
>>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>



-- 
Officially Certified TYPO3 Integrator


More information about the TYPO3-project-typo3v4mvc mailing list