I am working on Yii2. I have developed an API which will save the incoming records from the client. A client can send an image so I am saving its name and then uploading in the folder. Along with the name of the image I am also sending data with it. All the data except the image name are saved. Below is my API call.
public function actionAddnew()
{
$fp = fopen('preinstall.txt', 'w+');
fwrite($fp, file_get_contents('php://input'));
fclose($fp);
$inputs = json_decode(file_get_contents('php://input'));
return PreInstallations::saveAll($inputs);
}
The function saveAll is
public static function saveAll($inputs)
{
$coutner = 0;
$arr_status = [];
foreach ($inputs as $input) {
$s = new PreInstallations;
foreach ((array)$input as $key => $value) {
if ($key != 'image_names') {
if ($s->hasAttribute($key)) {
$s->$key = $value;
}
}
}
$user = Yii::$app->user;
if (isset($input->auth_key) && Users::find()->where(['auth_key' => $input->auth_key])->exists()) {
$user = Users::find()->where(['auth_key' => $input->auth_key])->one();
}
$s->created_by = $user->id;
if (PreInstallations::find()->where(['ref_no' => $input->ref_no])->exists()) {
$arr_status[] = ['install_id' => $input->install_id, 'status' => 2, 'messages' => "Ref # Already exists"];
continue;
}
$s->sync_date = date('Y-m-d H:i:s ');
if ($s->save()) {
if ($s->pre_install_status == 'Pre Installed') {
Meters::change_status_byinstall($s->meter_msn, Meters::$status_titles[8]);
}
$arr_status[] = ['install_id' => $input->install_id, 'status' => 1];
$coutner++;
if (isset($input->site_images_name)) {
foreach ($input->site_images_name as $img) {
$image2 = new PreInstallationImagesSite;
$image2->image_name = $img->image_name;
$image2->pre_install_id = $s->id;
$image2->save();
}
}
}
else {
$arr_status[] = ['install_id' => $input->install_id, 'status' => 0, 'messages' => $s->errors];
}
}
return ['status' => 'OK', 'details' => $arr_status, 'records_saved' => $coutner];
}
Below part of above code saves the images name
if (isset($input->site_images_name)) {
foreach ($input->site_images_name as $img) {
$image2 = new PreInstallationImagesSite;
$image2->image_name = $img->image_name;
$image2->pre_install_id = $s->id;
$image2->save();
}
}
For testing purpose API call is made from POSTMAN with below details
[{
"ref_no": "20371521444700U",
"meter_msn" :"002999001189",
"billing_msn" : "74516" ,
"latitude": "36.2703169",
"longitude": "78.178266",
"tarrif": "07",
"s_load": "07",
"customer_id" :"37010673625",
"pre_install_status": "Pre Installed",
"site_issues" : "No issue",
"install_id" : "20371521444700U_1521263491",
"created_date": "2018-03-17 10:12:12",
"consumer_name": "HDA PUMPING STATION SEVERAGE UNO.8 LATIFABAD HYD",
"consumer_address" :"HDA PUMPING STATION SEVERAGE UNO.8 LATIFABAD HYD",
"auth_key": "key",// replaced the original auth key with key
"ct_ratio": "200/5",
"ct_ratio_quantity":"4",
"cable_type":"37/83",
"cable_length":"11",
"atb_installed": "Yes",
"meter_type":"L.T.TOU",
"site_images_name":["20371521444700U_1522299780_site_1.jpg"]
}]
When I Send the request I am getting an error
{
"name": "PHP Notice",
"message": "Trying to get property of non-object",
"code": 8,
"type": "yii\\base\\ErrorException",
"file": "E:\\xampp\\htdocs\\inventory-web\\common\\models\\PreInstallations.php",
"line": 137,
"stack-trace": [
"#0 E:\\xampp\\htdocs\\inventory-web\\common\\models\\PreInstallations.php(137): yii\\base\\ErrorHandler->handleError(8, 'Trying to get p...', 'E:\\\\xampp\\\\htdocs...', 137, Array)",
"#1 E:\\xampp\\htdocs\\inventory-web\\api\\modules\\v1\\controllers\\PreinstallationController.php(36): common\\models\\PreInstallations::saveAll(Array)",
"#2 [internal function]: api\\modules\\v1\\controllers\\PreinstallationController->actionAddnew()",
"#3 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\base\\InlineAction.php(57): call_user_func_array(Array, Array)",
"#4 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\base\\Controller.php(156): yii\\base\\InlineAction->runWithParams(Array)",
"#5 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\base\\Module.php(523): yii\\base\\Controller->runAction('addnew', Array)",
"#6 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\web\\Application.php(102): yii\\base\\Module->runAction('v1/preinstallat...', Array)",
"#7 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\base\\Application.php(380): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))",
"#8 E:\\xampp\\htdocs\\inventory-web\\api\\web\\index.php(35): yii\\base\\Application->run()",
"#9 {main}"
]
}
The line 137 is $image2->image_name = $img->image_name;.
The Image model is
public function rules()
{
return [
[['pre_install_id'], 'required'],
[['pre_install_id', 'image_upload_flag'], 'integer'],
[['image_name'], 'string', 'max' => 255],
[['pre_install_id'], 'exist', 'skipOnError' => true, 'targetClass' => PreInstallations::className(), 'targetAttribute' => ['pre_install_id' => 'id']],
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'pre_install_id' => 'Pre Install ID',
'image_name' => 'Image Name',
'image_upload_flag' => 'Image Upload Flag',
];
}
I must be missing something that I don't know. Any help would be highly appreciated.
Related
I have registered yii\web\JsonParser as an application request’s parser in order to enable JSON input:
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
]
Now, I want my custom action to handle JSON requests like the following one:
{
"one": 11,
"two": 2,
"three": 33
}
I am doing this by using bodyParams (source of this idea):
$bodyParams = Yii::$app->request->bodyParams;
$one = $bodyParams['one'] ?? false;
$two = $bodyParams['two'] ?? false;
$three = $bodyParams['three'] ?? false;
The whole controller's code looks like this:
<?php
namespace api\controllers;
use Yii;
use yii\rest\ActiveController;
class UserController extends ActiveController
{
public $modelClass = 'common\models\User';
public function verbs()
{
$verbs = parent::verbs();
$verbs['test'] = ['GET'];
return $verbs;
}
public function actionTest()
{
$bodyParams = Yii::$app->request->bodyParams;
$one = $bodyParams['one'] ?? false;
$two = $bodyParams['two'] ?? false;
$three = $bodyParams['three'] ?? false;
return [
'params' => [
'one' => $one,
'two' => $two,
'three' => $three,
]
];
}
}
Is there a better way of doing so (i.e. reading JSON directly as action's parameters etc.)?
I am creating one API. In that I want to show buyers info, urls for their files/ images, and count in response. I have 3 tables buyers(PK: buyers_id), filedocs(FK: buyers_id), give_credit_transaction_master(FK: buyers_id). In those tables common column is buyers_id.
CODE
public function index()
{
$filedocsObj = FileDoc::with(['relBuyers'])->where('is_active','1')->get();
//return $filedocsCount;
$info = [];
// $profile_urls=[];
// $aadhar_urls=[];
// $pan_urls=[];
// $transaction_count=[];
// $info = array();
for($i = 0; $i < count($filedocsObj); $i++){
$buyer = FileDoc::Join('buyers', 'file_docs.buyers_id', '=', 'buyers.buyers_id')
->where('file_docs.buyers_id',$filedocsObj[$i]->buyers_id)
->select(
'buyers.buyers_id',
'buyers.buyers_name',
'buyers.buyers_address',
'buyers.buyers_contact_number',
'buyers.buyers_aadhar_number',
'buyers.buyers_pan_number',
'file_docs.buyers_profile_image',
'file_docs.buyers_aadhar_file',
'file_docs.buyers_pan_file',
)
->first();
// $info = $buyer->toArray();
array_push($info, [
'info' => $buyer
]);
// $info[] = $buyer;
$existProfile = Storage::disk('local')->exists('public/uploads/profile_images/'.$filedocsObj[$i]->buyers_profile_image);
if (isset($filedocsObj[$i]->buyers_profile_image) && $existProfile) {
// $profile_urls[$i] = Storage::disk('public')->url('/uploads/profile_images/'.$filedocsObj[$i]->buyers_profile_image);
array_push($info, [
'profile_url' => Storage::disk('public')->url('/uploads/profile_images/'.$filedocsObj[$i]->buyers_profile_image)
]);
//$info[] = Storage::disk('public')->url('/uploads/profile_images/'.$filedocsObj[$i]->buyers_profile_image);
}
else
{
// $profile_urls[$i]="";
array_push($info, [
'profile_url' => ''
]);
// $info[] = "";
}
$existAadhar = Storage::disk('local')->exists('public/uploads/aadhar_files/'.$filedocsObj[$i]->buyers_aadhar_file);
if (isset($filedocsObj[$i]->buyers_aadhar_file) && $existAadhar) {
//$aadhar_urls[$i] = Storage::disk('public')->url('/uploads/aadhar_files/'.$filedocsObj[$i]->buyers_aadhar_file);
array_push($info, [
'aadhar_url' => Storage::disk('public')->url('/uploads/aadhar_files/'.$filedocsObj[$i]->buyers_aadhar_file)
]);
// $info[] = Storage::disk('public')->url('/uploads/aadhar_files/'.$filedocsObj[$i]->buyers_aadhar_file);
}
$existPan = Storage::disk('local')->exists('public/uploads/pan_files/'.$filedocsObj[$i]->buyers_pan_file);
if (isset($filedocsObj[$i]->buyers_pan_file) && $existPan) {
//$pan_urls[$i] = Storage::disk('public')->url('/uploads/pan_files/'.$filedocsObj[$i]->buyers_pan_file);
array_push($info, [
'pan_url' => Storage::disk('public')->url('/uploads/pan_files/'.$filedocsObj[$i]->buyers_pan_file)
]);
//$info[] = Storage::disk('public')->url('/uploads/pan_files/'.$filedocsObj[$i]->buyers_pan_file);
}
$buyerTransactions = GiveCreditTransactionMaster::where('buyers_id',$filedocsObj[$i]->buyers_id)->get();
array_push($info, [
'transaction_count' => count($buyerTransactions)
]);
// $transaction_count[$i] = count($buyerTransactions);
// $resultSet = array_merge($info,$profile_urls,$aadhar_urls,$pan_urls,$transaction_count);
}
return $this->sendResponse($info, 'Buyers retrieved successfully.');
// return $this->sendResponse($resultSet, 'Buyers retrieved successfully.');
// return $this->sendResponse(array("Info" => $filedocs->toArray(),"profile_path" => $profile_urls, "aadhar_urls" => $aadhar_urls, "pan_urls" => $pan_urls, "transactionCountArray" => $transactionCountArray), 'Buyers retrieved successfully.');
}
In above code, I have taken one array info in which I am pushing query result buyer , iteration result profile_url, aadhar_url, pan_url, and another query result counts transaction_count. And returning info array as response.
MY API response:
{
"success": true,
"data": [
{
"info": {
"buyers_id": 2,
"buyers_name": "uuu",
"buyers_address": "dfgfgf",
"buyers_contact_number": "8986665576",
"buyers_aadhar_number": "654654654545",
"buyers_pan_number": "tytyr43242",
"buyers_profile_image": "2_B_profile_lady_profile.png",
"buyers_aadhar_file": "2_B_aadhar_aadhar_card_image.png",
"buyers_pan_file": "2_B_pan_pan_image.jpg"
}
},
{
"profile_url": "http://localhost/storage/uploads/profile_images/2_B_profile_lady_profile.png"
},
{
"aadhar_url": "http://localhost/storage/uploads/aadhar_files/2_B_aadhar_aadhar_card_image.png"
},
{
"pan_url": "http://localhost/storage/uploads/pan_files/2_B_pan_pan_image.jpg"
},
{
"transaction_count": 2
},
{
"info": {
"buyers_id": 28,
"buyers_name": "lili",
"buyers_address": "hjkhkdfgf",
"buyers_contact_number": "7856564656",
"buyers_aadhar_number": "343435353545",
"buyers_pan_number": "trtre34343",
"buyers_profile_image": "28_B_profile_test_profile.png",
"buyers_aadhar_file": "28_B_aadhar_test_aadhar.jpg",
"buyers_pan_file": "28_B_pan_test_pan.jpg"
}
},
{
"profile_url": "http://localhost/storage/uploads/profile_images/28_B_profile_test_profile.png"
},
{
"aadhar_url": "http://localhost/storage/uploads/aadhar_files/28_B_aadhar_test_aadhar.jpg"
},
{
"pan_url": "http://localhost/storage/uploads/pan_files/28_B_pan_test_pan.jpg"
},
{
"transaction_count": 0
}
],
"message": "Buyers retrieved successfully."
}
But in above response I am getting info of particular buyer separately than profile_url, aadhar_url, pan_url, transaction_count. Also profile_url, aadhar_url, pan_url, transaction_count this are getting separately.
I want all parameters(info,profile_url, aadhar_url, pan_url, transaction_count) of one buyer should come in one {}. How can I get that type of response?
I tried a lot using array_push, array_merge etc. But not getting requied response.
Please help. Thanks in advance.
This will help you with your desired response. I have manged your function. make it try and let me know if it helps you thanks
public
function index()
{
$filedocsObj = FileDoc::with(['relBuyers'])->where('is_active', '1')->get();
//return $filedocsCount;
$info = [];
// $profile_urls=[];
// $aadhar_urls=[];
// $pan_urls=[];
// $transaction_count=[];
// $info = array();
foreach ($filedocsObj as $index => $filedocsObjInfo) {
$buyer = FileDoc::Join('buyers', 'file_docs.buyers_id', '=', 'buyers.buyers_id')
->where('file_docs.buyers_id', $filedocsObjInfo->buyers_id)
->select(
'buyers.buyers_id',
'buyers.buyers_name',
'buyers.buyers_address',
'buyers.buyers_contact_number',
'buyers.buyers_aadhar_number',
'buyers.buyers_pan_number',
'file_docs.buyers_profile_image',
'file_docs.buyers_aadhar_file',
'file_docs.buyers_pan_file',
)
->first();
// $info = $buyer->toArray();
$info[$index]['info'] = $buyer;
// $info[] = $buyer;
$existProfile = Storage::disk('local')->exists('public/uploads/profile_images/' . $filedocsObjInfo->buyers_profile_image);
if (isset($filedocsObjInfo->buyers_profile_image) && $existProfile) {
$info[$index]['profile_url'] = Storage::disk('public')->url('/uploads/profile_images/' . $filedocsObjInfo->buyers_profile_image);
} else {
$info[$index]['profile_url'] = '';
}
$existAadhar = Storage::disk('local')->exists('public/uploads/aadhar_files/' . $filedocsObjInfo->buyers_aadhar_file);
if (isset($filedocsObjInfo->buyers_aadhar_file) && $existAadhar) {
$info[$index]['aadhar_url'] = Storage::disk('public')->url('/uploads/aadhar_files/' . $filedocsObjInfo->buyers_aadhar_file);
}
$existPan = Storage::disk('local')->exists('public/uploads/pan_files/' . $filedocsObjInfo->buyers_pan_file);
if (isset($filedocsObjInfo->buyers_pan_file) && $existPan) {
$info[$index]['pan_url'] = Storage::disk('public')->url('/uploads/pan_files/' . $filedocsObjInfo->buyers_pan_file);
}
$buyerTransactions = GiveCreditTransactionMaster::where('buyers_id', $filedocsObjInfo->buyers_id)->get();
$info[$index]['transaction_count'] = count($buyerTransactions);
// $transaction_count[$i] = count($buyerTransactions);
// $resultSet = array_merge($info,$profile_urls,$aadhar_urls,$pan_urls,$transaction_count);
}
return $this->sendResponse($info, 'Buyers retrieved successfully.');
// return $this->sendResponse($resultSet, 'Buyers retrieved successfully.');
// return $this->sendResponse(array("Info" => $filedocs->toArray(),"profile_path" => $profile_urls, "aadhar_urls" => $aadhar_urls, "pan_urls" => $pan_urls, "transactionCountArray" => $transactionCountArray), 'Buyers retrieved successfully.');
}
on PHP the following solution might work.
json_encode(array_merge(json_decode($a, true),json_decode($b, true)))
Try and let me know.
When you use an array_merge try json_decode your value like above.
I have a Symfony3 Application setup and would like to rebuild the frontend based on React now.
One of the Entities is User and each of them can have one or more Groups so in the HTML form a list of Checkboxes appears, so the admin can select the groups attached to a User.
In UserType.php this looks like that:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', TextType::class)
->add('password', TextType::class)
->add('email', EmailType::class)
->add('groups', EntityType::class, [
'class' => Group::class,
'choice_label' => 'name',
'expanded' => true,
'multiple' => true//,
//'data' => $builder->getData()->getGroups()
]);
}
To render the Form using React, it would be extremely handy to get a JSON response which could look like that:
{
"user": {
…
"groups": [<gid 1>, …]
"groups_available": [
{
"id": <gid 1>,
"name": …
},
…
]
}
}
So that the groups array contains all the ids of the groups, the user is attached to and groups_available a list of all available groups.
Right now I am using FOSRestBundle and in the Controller it looks like that:
public function getUserformAction($id=null)
{
//if the id is null, create a new user
//else get the existing one
…
$form = $this->createForm(UserType::class, $user);
$view = $form->createView();
return $this->handleView($view);
}
How can I do that?
you should try the following code:
->add('groups', EntityType::class, array(
//if Group is in AppBundle or use the required Bundle name
'class' => 'AppBundle:Group',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.name', 'ASC')
},
'choice_label' => 'name',
'multiple' => true,
'expanded' => true,
));
You can also get a reference from here
After digging in the source and with the help of the debugger I could manage to do it in a more less robust and generic way like so:
protected function getFormStructure(Form $form)
{
return $this->iterateFormview($form->createView(), []);
}
private function iterateFormview(FormView $view, array $result)
{
foreach($view as $child) {
$vars = $child->vars;
$data = ['value' => $vars['value']];
if(isset($vars['choices'])) {
$data['choices'] = [];
foreach ($vars['choices'] as $choice) {
array_push($data['choices'], [
'label' => $choice->label,
'value' => $choice->value]);
}
}
$result[$vars['full_name']] = $data;
if(count($child) > 0) {
$result = $this->iterateFormview($child, $result);
}
}
return $result;
}
Result (as json):
{
…
"user[groups]":
{
"value": "",
"choices": [
{
"value": 100,
"label": "the name"
},
…
]
}
}
I guess this routine needs to be extended if I need to support more types… But for now this will do it.
Hi i have an RESTfulAPI that return a JSON object like this:
{
data: [
{
id: 4,
name: "Naranja",
cant_portion: 2,
portion_name: "Piezas",
foodgroup_name: "Frutas"
}
]
}
and i want to rearrange it so i can have something like this:
{
data: [
{
foodgroup_name: "Frutas",
items:[
{
portion_name: "Piezas",
items:[
{
id: 4,
name: "Naranja",
cant_portion: 2,
}
]
}
]
}
]
}
the idea of doing this is that i want to have a nested ul and the first ul should give me the name of the foodgroup, then the next ul should give the type of portions that foodgroup has, and inside that ul to put some li, with the items that match those 2 requirements.
Now in my API i can return the name of each Food group, so i'm ok with that first ul but in the second one where the portions goes, not every foodgroup has all of the portions, just maybe 1 or 2.
Check it:
private function _rearrangeData($data = array())
{
$out = array();
if (!count($data)) {
return $data;
}
$foodgroup = array();
$portion = array();
$foodgroup_name = $data[0]['foodgroup_name'];
$portion_name = $data[0]['portion_name'];
foreach ($data as $item) {
if ($item['foodgroup_name'] == $foodgroup_name) {
if ($item['portion_name'] == $portion_name) {
unset($item['foodgroup_name']);
unset($item['portion_name']);
array_push($portion, $item);
} else {
$arr = [
'portion_name' => $portion_name,
'items' => $portion
];
$portion_name = $item['portion_name'];
unset($item['foodgroup_name']);
unset($item['portion_name']);
$portion = [$item];
array_push($foodgroup, $arr);
}
} else {
$arr = [
'portion_name' => $portion_name,
'items' => $portion
];
array_push($foodgroup, $arr);
$arr = [
'foodgroup_name' => $foodgroup_name,
'items' => $foodgroup
];
$foodgroup_name = $item['foodgroup_name'];
$portion_name = $item['portion_name'];
unset($item['foodgroup_name']);
unset($item['portion_name']);
$portion = [$item];
$foodgroup = [];
array_push($out, $arr);
}
}
$arr = [
'portion_name' => $portion_name,
'items' => $portion
];
array_push($foodgroup, $arr);
$arr = [
'foodgroup_name' => $foodgroup_name,
'items' => $foodgroup
];
array_push($out, $arr);
return $out;
}
Edit: with your db:
$food_group = DB::table('foods')->join('food_group', 'food_group.id', '=', 'foods.food_group_id')->groupBy('food_group_id')->get();
$out = [];
foreach ($food_group as $item) {
$foods = DB::table('foods')->join('portions', 'portions.id', '=', 'foods.portion_id')->where('food_group_id', $item->id)->groupBy('portion_id')->get();
$arr1 = [];
foreach($foods as $item2) {
$por_food = DB::table('foods')->where('food_group_id',$item->id)->where('portion_id',$item2->id)->get();
$arr = [
'portion_name' => $item2->name,
'items' => $por_food
];
array_push($arr1, $arr);
}
$arr2 = [
'foodgroup_name'=>$item->name,
'items'=>$arr1
];
array_push($out, $arr2);
}
return response()->json(['data'=>$out],200);
I used karthik grid view and editable column to edit my grid view data. it not work for the first row of the grid view and work for the other rows when i enter value to the first row it give error like this
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
my gridview code is.
<?= GridView::widget([
'dataProvider' => $dataProvider,
'pjax' => true,
'pjaxSettings' => [
'options' => [
'id' => 'grid',
]
],
'export'=>false,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'header'=>'Sub Category',
'value'=>'item.subCategory.name',
],
'item.code',
[
'header'=>'Brand',
'value'=>'item.brand.name',
],
'item.description',
'item.pack_size',
[
'header'=>'Unit',
'value'=>'item.unit',
],
[
'header'=>'Last Price',
'value'=>function($model){
$customerId = $model->customerOrderRequest->customer_id;
$lastPurchasedPrice = Item::getLastPurchasedPrice($customerId,$model->item_id);
return '$ ' . number_format($lastPurchasedPrice, 2);
}
],
[
'class' => 'kartik\grid\EditableColumn',
'attribute'=>'qty',
'editableOptions' =>
[
'formOptions' => ['action' => 'customer-order-request']
],
'header' => 'Qty',
],
[
'header'=>'Estimate',
'value'=>function($model)
{
return '123123.00';
}
],
[
'header'=>'Price (UNIT)',
'format'=>'raw',
'value'=>function($modal){
$salse_rep_id = Yii::$app->user->identity->ref_id;
$exsist_respond = Respond::find()->where(['sales_rep_id'=>$salse_rep_id,'customer_order_request_id'=>$modal->customer_order_request_id])->one();
if(!empty($exsist_respond)){
$exsist_respond_item = RespondItem::find()->where(['item_id'=>$modal->item_id,'respond_id'=>$exsist_respond->id])->one();
if(!empty($exsist_respond_item)){
$price = $exsist_respond_item->price;
} else {
$price = NULL;
}
} else {
$price = NULL;
}
if(!empty($exsist_respond) && $exsist_respond->status !="Pending"){
return $price;
}else{
return "<input type='text' class='respond-item' cor='$modal->customer_order_request_id' value='$price' item_id='$modal->item_id' />";
}
},
'visible'=>(Yii::$app->user->identity->ref_table =="sales_rep")? true:false
],
],
]); ?>
and my controller is
public function actionEditable()
{
if (Yii::$app->request->post('hasEditable'))
{
$customerItemsId = Yii::$app->request->post('editableKey');
print_r($customerItemsId);die();
$model = RequestItem::findOne($customerItemsId);
$out = Json::encode(['output'=>'', 'message'=>'']);
$post = [];
$posted = current($_POST['RequestItem']);
$post['RequestItem'] = $posted;
if ($model->load($post))
{
$model->save();
$output = '';
$out = Json::encode(['output'=>$output, 'message'=>'']);
}
echo $out;
return;
}
}
any one can help me with this problem.
Form tag nested.
a trick: Add a fake form to let browser remove it.
I meet this problem today, cause I put a form in another, they are nested.
So the browser remove the first nested form.
In the official W3C XHTML specification, Section B. "Element Prohibitions", states that:
"form must not contain other form elements."
official website
Following is sample code:
<form id="thisisMainForm">
<form id="dummy"> ->This will get Removed
<gridview id="thisisEditableGridView">
Gridviewcode.....
</gridview>
</form>
</form>