cakePHP로 간단한 웹 응용 프로그램을 만들기 시작했고 작업에서 코드 중복을 피할 수 있는지 궁금합니다. 나는 두 가지 모델을 가지고와 해당 컨트롤러 모두 소폭 다른 코드와 같은 동작 (인덱스,보기, 편집, 추가, 삭제), 예를 들면 포함 :CakePHP : 컨트롤러 동작에서 코드 중복 피하기
는트랜잭션 컨트롤러는
public function add() {
if ($this->request->is('post')) {
$this->Transaction->create();
if ($this->Transaction->save($this->request->data)) {
$this->Session->setFlash(__('The transaction has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The transaction could not be saved. Please, try again.'));
}
}
}
두 번째 컨트롤러는 것을 add()
조치, 다른 모델에만 적용하십시오 (예 : transaction
을 trades
으로 바꿉니다).
이런 종류의 코드 중복을 피할 수있는 방법이 있습니까?
매우 사실 ... 그에게 맡기십시오 ... – Anubhav