CakePHP 앱에서 dynamiccaly 양식 필드를 추가하는 데 문제가 있으며 해결 방법을 모르겠습니다. EventsController/add.ctp에 양식을 추가하고 싶습니다. Events.name, Dates.from, Dates.to, Dates.endregister, Dates.location_id, {optional more Dates.from, Dates.to ...}, Terms_mem.teacher_id {및 옵션 더 Terms_mem.teacher_id은} 내 테이블은 다음과 같습니다동적으로 양식 필드 추가
가CREATE TABLE `events` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` varchar(150) NOT NULL
);
CREATE TABLE `dates` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`from` datetime NOT NULL,
`to` datetime NOT NULL,
`endregister` datetime,
`event_id` int(11) NOT NULL,
`location_id` int(11) NOT NULL,
FOREIGN KEY (`event_id`) REFERENCES `events`(`id`),
FOREIGN KEY (`location_id`) REFERENCES `locations`(`id`)
);
CREATE TABLE `locations` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`street` varchar(70),
`city` varchar(70) NOT NULL
);
CREATE TABLE `dates_mem` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`teacher_id` int(11) NOT NULL,
`date_id` int(11) NOT NULL,
FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`),
FOREIGN KEY (`date_id`) REFERENCES `dates`(`id`)
)
그래서 형태가 보일 것 같은 :
<?php echo $this->Form->create('Event'); ?>
<fieldset>
<?php
// events
echo $this->Form->input('name');
// dates
echo $this->Form->input('from');
echo $this->Form->input('to');
echo $this->Form->input('endregister');
echo $this->Form->input('location_id');
/* HERE optional dynamically add next inputs for dates (from, to, ...) */
// teachers
echo $this->Form->input('teacher_id');
/* HERE optional dynamically add next inputs for teachers(teacher_id) */
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
그리고 해당 테이블에 저장 필드가 결국
. 이것은 CakePHP, 버전 2.4에서 가능합니까? 그렇다면, 도와 주시겠습니까?편집 :
버줌 썼다 :
$this->Form->input('Date.0.from');
$this->Form->input('Date.0.to');
$this->Form->input('Date.1.from');
$this->Form->input('Date.1.to');
그것으로 할 수 있나요? 따라서 Date.1.from 및 Date.1.to은 버튼을 클릭
$this->Form->input('Date.0.from');
$this->Form->input('Date.0.to');
// button add next date
$this->Form->input('Date.1.from'); // after click on add next date
$this->Form->input('Date.1.to'); // after click on add next date
// button add next date
$this->Form->input('Date.2.from'); // after click on add next date
$this->Form->input('Date.2.to'); // after click on add next date
// button add next date
감사합니다. 제 편집문을 보시겠습니까? – user3027356
내 대답도 업데이트되었습니다. – burzum