[TYPO3-mvc] Putting together a object for updateAction, from ExtJs/json
Dmitri Pisarev
dimaip at gmail.com
Thu Mar 18 06:16:58 CET 2010
Hi Dennis,
now I understand.
I was using simple form submits with params, and for JsonReader I
configured a viewhelper. Never used JsonWriter though.
I shall look deeper into it once I encounter JsonWriter, there must be
possible to do something with!
Regards,
Dmitri.
On 17.03.2010 16:06, dennis ahrens wrote:
> Hi Dmitri,
>
> I don't know how to configure the JsonReader and the JsonWriter to
> match the expected structure. If you're using a default store
> configured with autoSave:true and writeAllFields: false the data is
> placed automatically in an HTTP parameter called data. I think the
> name 'data' is caused by the reader configuration, which wants it's
> data in a json object property called data:
>
> the configuration object for the Reader looks like this:
>
> {totalProperty: 'total', successProperty: 'success', idProperty:
> 'uid', root: 'data', fields:[....]}
>
> The Reader can interpret reponse data which looks like this:
> {"message":"foo","total":0,"success":true,"data":[]}
>
> When using the CRUD features shipped by extjs the described HTTP
> request param named 'data' is send to the server.
>
> regards
> Dennis
>
> 2010/3/17 Dmitri Pisarev<dimaip at gmail.com>:
>> Hi Dennis,
>> I still don't understand why not to create a proper object in ExtJS right a
>> way, as in my example. Why do you ever have to access _POST directly?
>>
>> On 17.03.2010 12:54, dennis ahrens wrote:
>>>
>>> Hi Dmitri,
>>>
>>> the data comes in one POST/GET parameter and is encoded in json. The
>>> "problem" is the loacation (in the code) where to apply the data to
>>> the php-object. Of course it feels much better when the action
>>> receives a modified object where the json data is applied instead of
>>> the array containing the changes.
>>> For fluid templates the magic is done when initializing the controller
>>> and it's action. I think the implementation should be done at the
>>> same location.
>>> Can anyone give a cleaner view for this scenario?
>>>
>>> regards
>>> Dennis
>>>
>>> 2010/3/17 Dmitri Pisarev<dimaip at gmail.com>:
>>>>
>>>> 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
>>>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>
More information about the TYPO3-project-typo3v4mvc
mailing list