다음과 비슷한 테이블 내에 폼이 있습니다.이 폼을 제출하면 입력에 따라 여러 개의 새 리소스를 만들어야하는 Modx 스 니펫이 있습니다. 배열이 통과합니다.폼에서 여러 개의 Modx 리소스를 만들려고 시도합니다.
<table class="table responsive-table">
<thead>
<th>pagetitle</th>
<th>longtitle</th>
</thead>
<tbody>
<tr>
<td><input type="text" name="pagetitle[]" value="" /></td>
<td><input type="text" name="longtitle[]" value=""/></td>
</tr>
<tr>
<td><input type="text" name="pagetitle[]" value="" /></td>
<td><input type="text" name="longtitle[]" value=""/></td>
</tr>
</tbody>
</table>
아래 사항이 실행될 때 어떤 일이 발생하는지는 예상대로 새 리소스를 생성하지만 모든 필드는 "어레이"로 설정됩니다. 배열의 값이 아닙니다. $allFormFields
에
<?php
$allFormFields = $hook->getValues();
foreach ($allFormFields as $key => $value)
{
$doc = $modx->newObject('modResource');
$doc->set('createdby', $modx->user->get('id'));
$doc->set('pagetitle', $value['pagetitle']);
$doc->set('longtitle', $value['longtitle']);
$doc->save();
}
return true;
개체의 fromArray 메서드는 여러 개의 set 메서드 대신 유용 할 것이라고 생각합니다. – proxyfabio