how to convert to json from post in Yii2 - json

I want to create json from multiple selection from listbox in yii2 after post i receive following data
categorymodel[0]=11&categorymodel[1]=12&categorymodel[2]=13
how to convert to json data and store in db.
json data like {"11","12","13"}

Once you have the proper array you can use eg:
$retJSON= json_encode($categoryModel);

Related

Laravel generate forms with JSON

Is there a way in Laravel to save JSON code in one table field and when you load that JSON code you get generated form (view) where you can submit data that can be saved in JSON code and then again saved in one table field?
you can use Redis.
$formData = Redis::set('formdata',$json);
$formData = Redis::get('formdata');

Save api json to database using laravel

Is it possible to get data from an api url and save it directly to database when working with laravel? the data i get from the url is of the format {"name":"100KVA SUKAM Generator","level":"5.965"}.
Yes, you can create table with json type field (or text) and keep data there:
$table->json('data_from_api');
https://laravel.com/docs/5.2/migrations#writing-migrations
If you want to persist data as usual data, you can use mass assignment. First, convert JSON to an array with [json_decode][1] and save data like that:
$data = json_decode($jsonData, true)
Model::create($data);
Don't forget to add all columns to a $fillable property of a model.

JSON data in spring model

Its a spring based web application. I have a data table in the screen. In my understanding, data table accepts only data in JSON format. so i have a field(String) in my model for holding data table data, the same will be hidden in the screen. Upon listing(form submit not ajax), I would serialize the list to JSON data and keep it in the model. In Javascript, I would populate the data table using the data in the hidden field. It works fine but i have a doubt like whether it is a correct approach ?
I have a export to excel functionality. I would pass the model in the ajax call and get the data from the model and create the XLSX file. Issue is if the data has 3000 records, it works fine but when the record get increases say 4000 the data in the model is coming as null in the handler. Is there any data size limit for the Spring to bind the value to model ?
To your first question, the approach which you are following is correct.
For Export Excel functionality, you can pass the same JSON string which you stored in a hidden variable. And DE-serialize the JSON string to the data. Since JSON is just a string, there is no such limit on Ajax form data

Flowgear Insert form post data into database

How to insert post data into database using flowgear API? I am done inserting data using get but html form post method is not work using flowgear API. Please explain how it is acheive in flowgrear.
I have this URL
http://www.somedomain.com/api/flow-test
When I hit enter it is return JSON value
{
"message" : "message send successfully",
"statusCode" : "1"
}
This JSON value store into database using flowgear post method.
If you want to POST some data to a Flowgear API endpoint and then ingest that into a database, add the special property FgRequestBody on to a Variable Bar to receive the POST data.
If it's in JSON format, use JSON Convert to convert it to XML, then push it through a transform (XSL Transform or QuickMap) if it's layout doesn't match your target database.
Finally, use an SQL Table Update to insert to the data into the database.
When calling a Flowgear Workflow using an API call, the Workflow can respond with a specific body using the FgResponseBody and FgResponseContentType variables on the Variable Bar.

In yii how json formatted inputs are inserted into tables

I am creating project using extjs and yii. My client side design is in extjs-4 and server side design is in yii framework.
Now I am having table Poll with fields as:
pollid
pollQuestion
Isactive
Userid
And Polloption:
pollid
option
Now during creation of new pole,poll creation view form which is designed in extjs will receive inputs and will send this data to server side in json format as-
{
'success':true,
'results':[ {
'pollid' : 1,
'pollQuestion' : 'Which is capital of india',
}
{ options from polloption table in json format
}]
}
So at server side all this values will come in json format. So now in yii i want to insert this received inputs in corresponding poll tables fields.
So how Yii will convert this json formatted inputs and also insert those values into repective fields of poll table. Please help me.
Your question is very vague and general. Here's an overview of what you'll want to do:
submit the data to a Yii controller
If the data is in the body, use PHP's file_get_contents. If you POST or GET it, you can use Yii's CHttpRequest::getParam to read in the raw JSON
use CJSON::decode() to parse the JSON into a PHP array
manipulate the array values, and build a new array
return the data (echo or print it if you just need the raw JSON and don't need a view). You'll probably want to return JSON again to use it in extjs4, so you'll want to use the CJSON::encode() method