CakePHP3의 patchEntities 사용법에 대해
2865 단어 cakephp3
CakePHP3의 patchEntities 사용법에 대해
Cookbook3 를 보고 이마이치 사용법을 모르기 때문에 조사해 보았습니다.
결론을 먼저 쓰면 여러 레코드의 데이터를 일괄적으로 패치해 주는 것이었다
조속히 사용해 보기
이번에 준비한 DB 테이블

※postgreSQL입니다
Post 데이터를 만드는 화면

브라우저의 개발자 도구로 보면 이런 느낌

※name 속성이 배열이 되어 있어, 1년분이라고 하는 것으로 12개 있는 것이 됩니다.
Post되는 데이터 확인
patchEntities
에 인수로서 건네주기 때문에 먼저 내용을 확인
dump($this->request->data);

문제의 patchEntities를 사용해보십시오.
이런 식으로 사용
$entities = $table->patchEntities($entities, $this->request->data('MonthlyMarks'));
· args1 : entity의 배열 데이터
· args2 : post의 배열 데이터
제대로 검증도 해줍니다.

레코드 단위로 처리해 줍니다.
굉장한 편리!
절각이므로 patchEntities 된 entities를 Save 해 본다
patchEntities
다음 행에 설명
if ($table->saveMany($entities)) {
$this->Flash->success(__d($pluralar, 'The {0} has been saved', __(Inflector::camelize($pluralar))));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__d($pluralar, 'The {0} could not be saved', __(Inflector::camelize($pluralar))));
무슨 일이야?
단적으로 말하면 patcheEntities
가 Entity
단위로 처리해 줍니다. (복수형인가 (ry
그리고 patchEntities
된 것을 최종적으로 saveMany
로 일괄 보존하고 있습니다.
(CakePHP2의 SaveAll처럼 할 수 있습니다)
움직이지 않으면
patcheEntities
인수가 잘못되었습니다.
・args1: entityの配列構造
로 되어 있는 것
・args2: postデータがpatchできる配列構造
로 되어 있는 것
이 근처를 확인해 봅시다.
요약
여러 레코드의 일괄 저장이 있는 경우 patchEntities
와 saveMany
를 사용합시다.
Reference
이 문제에 관하여(CakePHP3의 patchEntities 사용법에 대해), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tsukabo/items/f9dd1bc0b9a4795fb66a
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
이번에 준비한 DB 테이블

※postgreSQL입니다
Post 데이터를 만드는 화면

브라우저의 개발자 도구로 보면 이런 느낌

※name 속성이 배열이 되어 있어, 1년분이라고 하는 것으로 12개 있는 것이 됩니다.
Post되는 데이터 확인
patchEntities
에 인수로서 건네주기 때문에 먼저 내용을 확인dump($this->request->data);

문제의 patchEntities를 사용해보십시오.
이런 식으로 사용
$entities = $table->patchEntities($entities, $this->request->data('MonthlyMarks'));
· args1 : entity의 배열 데이터
· args2 : post의 배열 데이터
제대로 검증도 해줍니다.

레코드 단위로 처리해 줍니다.
굉장한 편리!
절각이므로 patchEntities 된 entities를 Save 해 본다
patchEntities
다음 행에 설명if ($table->saveMany($entities)) {
$this->Flash->success(__d($pluralar, 'The {0} has been saved', __(Inflector::camelize($pluralar))));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__d($pluralar, 'The {0} could not be saved', __(Inflector::camelize($pluralar))));
무슨 일이야?
단적으로 말하면
patcheEntities
가 Entity
단위로 처리해 줍니다. (복수형인가 (ry그리고
patchEntities
된 것을 최종적으로 saveMany
로 일괄 보존하고 있습니다.(CakePHP2의 SaveAll처럼 할 수 있습니다)
움직이지 않으면
patcheEntities
인수가 잘못되었습니다.・args1:
entityの配列構造
로 되어 있는 것・args2:
postデータがpatchできる配列構造
로 되어 있는 것이 근처를 확인해 봅시다.
요약
여러 레코드의 일괄 저장이 있는 경우
patchEntities
와 saveMany
를 사용합시다.
Reference
이 문제에 관하여(CakePHP3의 patchEntities 사용법에 대해), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tsukabo/items/f9dd1bc0b9a4795fb66a텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)