2011-10-06 8 views
0

나는 운이없는 며칠 동안 연구 한 문제에 집착하고 있습니다. 여기에 대한 답은 일반적으로 나타납니다.프로그래밍 방식으로 위치 데이터 설정

$edit = array(); 
$edit['uid'] = $user->id; 
$edit['name'] = $user->name; 
$edit['status'] = 1; 
$edit['taxonomy'] = array($term_id); 
$edit['title'] = $Title; 
$edit['body'] = $body; 

등 ... 다음

와 함께 저장 : 모두가 완벽하게 작동

node_invoke_nodeapi($edit, $nType); 
node_validate($edit); 
if ($errors = form_get_errors()) { 
     print_r($errors); 
} 

$node = node_submit($edit); 
node_save($node); 

나는 형태로 제공하는 데이터에서 노드를 추가 사용자 정의 모듈 코드가 있습니다. 하지만 제공된 (위생 처리 된) zip 필드를 기반으로 각 노드에 위치 데이터를 추가하려고합니다.

gmap 및 위치 모듈이 설치되어 작동 중입니다. Drupal 컨텐츠 편집기를 사용하여 zip을 직접 추가하면 모든 기능이 작동합니다. 심지어보기 gmap. 그래서 버전과 개조자는 모두 정확하다는 것을 압니다. 와 국가 요소없이

$location['country'] = "US"; 
$location['postal_code'] = $zip; 
$locationID = location_save($location); 

:

$location = array(
'country' => 'US', 
'postal_code' => $zip, 
); 
$locationID = location_save($location); 

이 :

나는 이것을 사용했습니다. 다음 노드 데이터 초기화 섹션 (위)이 :

$edit->locations[0]['lid'] = $locationID; 

또는

if($locationID) $edit['field_location'][0]['lid'] = $locationID; 

또는
if($locationID) $edit['location'][0]['lid'] = $locationID; 

그러나이 중 어느 것도 작동하지 않습니다. 제출은 실제로 확인을 통과하지만 위치 데이터는 저장되지 않습니다. 그리고 아무런 오류도 발생하지 않았습니다.

이 문제에 도움을 주시면 매우 감사하겠습니다.

$locations = array(); 
$locations[0]['postal_code'] = $zip; 

$criteria = array(); 
$criteria['nid'] = $node->nid; 
$criteria['vid'] = $node->vid; 
$criteria['genid'] = 'NAME OF NODE TYPE HERE'; 

location_save_locations($locations, $criteria); 

I :

답변

2

내가 얻을이 먼저 노드를 만든 다음에 노드에 위치 데이터를 추가하여, (경우에 사람이시 동일한 문제와 비틀 거림을 가지고있다), 작동하도록 않았다 location_save_locations는 location_save가 아니라 올바른 방법입니다. 당신의 접근 방식에 따라

0

, 라인 4에 location_save_locations 넓은에 의해 노출, 당신이있는 위치를 업데이트 할 수 있습니다 저장된 위치의 뚜껑을 돌려 location_save

  • :

    location_save($locations[$key], TRUE, $criteria); 
    

    몇 가지 참고 사항을 위치가 "비어있는"경우 FALSE를 반환합니다.

  • 새 엔티티 위치의 새로운보기 (예 : node_load 데이터가 캐시 될 수 있음)에 대해 캐시를 지우거나 데이터베이스 (mysql> SELECT * FROM location ORDER BY lid DESC limit 6)를 쿼리하십시오.

    // A) give to the $node field an updated location 
        $node->field_location['und'][0] = $location; 
        // B) Save node with updated location 
        node_save ($node);  
    
    : 당신이 위치 필드를 가진 개체를 처리하는 경우

또는, 당신은 같은 청소기 뭔가를하려고 할 수 있습니다

관련 문제