Quantcast
Viewing all articles
Browse latest Browse all 2189

Extension Writers Discussion • Problem sending POST data to my controller

Hello everyone.

I am making my first extension, to test some extension development features.

I was trying send data from a view to one controller. I can get thsi using Get and LamedParameters in the path. But When I try make this using post never read my params. I will try show you my problem (I hope you can help me with this)

I make a POST request like this:

Code:

http://localhost:8000/app.php/genaut/translateRequest Method: POSTRequest Payload: {"text":"This is an example post in your phpBB3 installation. Everything seems to be working. You may delete this post if you like and continue to set up your board.","lang_target":"es"}
I have this routing config (Route without parameters because in Post method are not neccessary):

Code:

genaut_posttranslator_route:    path: /genaut/translate    defaults: { _controller: genaut.posttranslator.controller.translator_controller:translate}    methods: [POST]
In my controller "translate" method, I have this:

Code:

public function translate($text, $lang_target){    $translation_response = $text;    if(empty($text) || empty($lang_target)){$translation_response = 'Cant\'t translate (Not received info). Original text:' . $text;    }    }
I am getting this error:

Code:

{message : "Falta el valor para el argumento #1: <strong>text</strong> en la clase <strong>genaut\\posttranslator\\controller\\translator_controller:translate</strong>"}
Before, I tested with a GET configuration like this (or something like this) and worked fine:

Code:

genaut_posttranslator_route:    path: /genaut/translate/{text}/{lang_target}    defaults: { _controller: genaut.posttranslator.controller.translator_controller:translate}
So I think that I am missing something in the routing. I tried too using request class to get the post variables using "is_set_post" and ohter functions but nothing retrieve me data. Any idea?

Statistics: Posted by Juanla — Mon Apr 01, 2024 12:33 am



Viewing all articles
Browse latest Browse all 2189

Trending Articles