2015-01-08 2 views
1

저는 프로그램에 약간의 문제가 있으며 PHP에는별로 경험이 없습니다. html 형식의 객체 배열을 PHP 파일로 전송하려고합니다. 당신은 내가 만 입력 숨겨진 가치의 배열을 인쇄하는 것을 볼 수 있습니다html 형식의 객체 배열을 전송할 수 없습니다.

<form action="action/add_items.php" method="POST"> 
     <table border="1" width="20%"> 
      <thead> 
      <th> 
       <?= $lang["location_task"][$location->getProperty("location_id")][$location_task->getProperty("location_task_id")]; ?> 
      </th> 
      </thead> 
      <tbody> 
      <?php 
      $location_task_items = $location_task->getProperty("location_task_items"); 

      foreach ($location_task_items as $location_task_item) { 
       ?> 
       <tr> 
        <td> 
         <?= $lang["item"][$location_task_item->getProperty("location_task_item_id")]; ?> 
        </td> 
        <td> 
         <?= $location_task_item->getProperty("location_task_item_value"); ?> 
        </td> 
       </tr> 
      <?php 
      } 
      ?> 
      <tr> 
       <td></td> 
       <td> 
        <input type="hidden" value="<?php print_r($location_task_items); ?>" name="location_task_items"/> 
        <input type="submit" value="start"/> 
       </td> 
      </tr> 
      </tbody> 
     </table> 
    </form> 

location.php (실행 파일 형태의) : 우선 난 당신이 내 코드에 대해 살펴 보겠습니다됩니다. 그게 맞습니까?

add_items.php

$location_task_items = $_REQUEST["location_task_items"]; 

foreach($location_task_items as $location_task_item) { 
    if($Player_Has_ItemsClass->getObjectByIds($player_id, $location_task_item->getProperty("location_task_item_id")) == null) { 
     $player_has_items_attributes = array(); 
     $player_has_items_attributes["player_has_items_player_id"] = $player_id; 
     $player_has_items_attributes["player_has_items_item_id"] = $location_task_item->getProperty("location_task_item_id"); 
     $player_has_items_attributes["player_has_items_item_value"] = $location_task_item->getProperty("location_task_item_value"); 

     $player_has_items = new Player_Has_Items($player_has_items_attributes); 

     $Player_Has_ItemsClass->insertObject($player_has_items); 
    } else { 

    } 
} 
난 단지 문자열로 배열 add_items.php에서 foreach 문에이 예외 얻을

: 나는 또한로 json_encode과 json_decode과 그것을 시도

Invalid argument supplied for foreach()

를 :

print_r(json_encode($location_task_items)) 
json_decode($_REQUEST["location_task_items"]); 

하지만 get (object attribu TES)를 공개했다 : 당신을 위해

Call to undefined method stdClass::getProperty()

덕분에 당신은 할 수 :

+0

그런 식으로 배열을 인쇄 할 수 없습니다. 또한, 나는'print_f'가 일이라고 생각하지 않습니다 ... – imtheman

+0

배열을 문자열로 얻으려면 쉼표로 구분합니까? 그렇다면 PHP 디버그 함수를 찾으십시오. – user3479671

+0

"Array ([0] => Location_Task_Item 객체 ([location_task_item_id] => 100 [location_task_item_value] => 10))"하지만 "is_array"는 false를 표시합니다. . –

답변

0

json_encode 다음 귀하의 목적지에서 json_decode :

<input `type="hidden" value='<?php echo json_encode($location_task_items); ?>' name="location_task_items"/>` 
+0

동일한 예외가 발생하고 $ _REQUEST [ "location_task_items"]가 NULL입니다./ –

+0

양식 페이지의 원본을 먼저 확인하고 필드에 값을 인쇄하는지 확인하십시오! Json_decode의 사용법을 확인하십시오. @ 올리 노. – SaidbakR

+0

괜찮습니다. json_encode ($ location_task_items)의 var 덤프가 다음과 같이 표시됩니다. string (65) "[{{location_task_item_id": "100", "location_task_item_value": "10"}] " –

0

도움이 숨겨진 필드 사용에

<input type="hidden" value="<?php echo serialize($location_task_items); ?>" name="location_task_items"/> 

다음

$location_task_items = unserialize($_REQUEST["location_task_items"]); 
+0

그것을 시도했다. 같은 예외가 발생하고 그것을 인쇄 할 수 없습니다 :/ –

+0

$ location_task_items 배열입니까? var dump는 어떻게 생겼습니까? –

+0

var dump는 다음과 같이 보입니다 : –

관련 문제