2014-07-08 1 views
0

CakePHP의 부모보기에서 자식을 추가하려고합니다. 의미, 코스보기에서 코스에 추가하려는 수업이 있습니다.부모보기 CakePHP에 자식 추가

<div class="lessons form"> 
<?php echo $this->Form->create($course['Lesson']); ?> 
    <fieldset> 
     <legend><?php echo __('Add Lesson'); ?></legend> 
    <?php 
     echo $this->Form->input('name'); 
     echo $this->Form->input('description'); 
     echo $this->Form->input('course_id', array(
      'value'=>$course['Course']['id'] 
      )); 
    ?> 
    </fieldset> 
<?php echo $this->Form->end(__('Submit')); ?> 
</div> 

그러나 그것은 그것을하지 않는 것 : A $ 코스 [ '레슨'] 추가 -

나는 간단한 양식 도우미를 통해 그 일을 시도.

컨트롤러/모델에서 뭔가가 누락 되었습니까?

+0

$ this-> 서식 -> 생성 – Fury

+0

(// 여기에 모델 이름이 아닌 배열 //입니다) @ : 당신은 당신의 데이터 양식 제출 한 후 확인해야합니다이 경우구조로 아래는 IsaacRajaei Cake는 레슨보기에 있지 않지만 참조를 인식합니까? – itamar

+0

@IsaacRajaei 'course_id'가 올바르게 채워지지 않습니다. 그것은 나에게 빈 드롭 다운을주고있다. – itamar

답변

0

의 생각하자 물론 컨트롤러

// 물론 컨트롤러

public function add_lesson() { 
     if ($this->request->is('post')) { 
      $this->Lesson->create(); 
      if ($this->Lesson->save($this->request->data)) { 
       $this->Session->setFlash(__('The Lesson has been saved.')); 
       return $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The Lesson could not be saved. Please, try again.')); 
      } 
     } 

    $this->set('courses', $this->Course->find('list')); 
} 

// add_Lesson보기

<?php echo $this->Form->create('Lesson', array('url' => array('controller'=>'courses', 'action'=>'add_lesson'))); ?> 
    <fieldset> 
     <legend><?php echo __('Add Lesson'); ?></legend> 
    <?php 
     echo $this->Form->input('name'); 
     echo $this->Form->input('description'); 
     echo $this->Form->input('course_id'); 
    ?> 
    </fieldset> 
<?php echo $this->Form->end(__('Submit')); ?> 
+0

코스보기입니까? – itamar

+0

코스보기에서 새 수업을 만들려고합니다. (코스 HasMany 레슨) – itamar

+0

레슨보기 추가 – Fury

0

당신이이 같은 데이터를 저장할 수있는 코스 컨트롤러를 사용하려면 :

$this->Course->Lesson->save($this->request->data); 
array(
     'Course' => array(
         'id' => 1 
         ), 
     'Lesson' => array(
         'name' => 'name' 
         'description' => 'balbalbala' 
         'course_id' => 1 
         ), 
); 
+0

오늘 나중에 다시 해보겠습니다. – itamar