2014-03-05 2 views
1

영화에는 많은 youtubeclips가있을 수있는 일대 다 관계가 있습니다. 필자는 모델을 만들고 업데이트 양식 내에 영화 데이터를 표시 할 수있었습니다. 이제는 일종의 루프를 만들어 내 많은 관계 데이터를 양식에 넣을 수 있어야합니다.하지만 어떻게 할지를 파악하는 것 같습니다. 이것은 내가 지금까지 가지고있는 것입니다.Yii - 일대 다 업데이트 양식

MovieController -

public function actionUpdate($id) 
{ 


    $model=$this->loadModel($id); 
    $modelYoutubeVideo=$this->loadYoutubeVideoModel($id); 
    $modelTwitterFeed=$this->loadTwitterModel($id); 

    if(isset($_POST['Movie'])) 
    { 
     $model->attributes=$_POST['Movie']; 
     if($model->save()) 
      $this->redirect(array('view','id'=>$model->id)); 
    } 

    $this->render('update',array(
     'model'=>$model, 
     'modelYoutubeVideo'=>$modelYoutubeVideo, 
     'modelTwitterFeed'=> $modelTwitterFeed 
    )); 
} 

업데이트 양식 -

<div class="row clone"> 
    <?php echo $form->labelEx($modelYoutubeVideo,'embed_code'); ?> 
    <?php echo $form->textField($modelYoutubeVideo,'embed_code[]',array('size'=>50,'maxlength'=>50)); ?> 
    <?php echo $form->error($modelYoutubeVideo,'embed_code'); ?> 

    <?php echo $form->labelEx($modelYoutubeVideo,'description'); ?> 
    <?php echo $form->textField($modelYoutubeVideo,'description[]',array('size'=>50,'maxlength'=>250)); ?> 
    <?php echo $form->error($modelYoutubeVideo,'description'); ?> 
</div> 
<?php 
    $this->widget('ext.widgets.reCopy.ReCopyWidget', array(
     'targetClass'=>'clone', 
    )); 
?> 

많은 관계 선박 테이블에서 내 데이터를 출력하는 루프를 작성해야합니다 -

<?php 
    for ($i = 0; $i < count($modelYoutubeVideo); ++$i) { 

     ($modelYoutubeVideo->embed_code[i]); 
     ($modelYoutubeVideo->embed_code[i]); 

    } 
?> 
을3210

영화 관계 - 당신이 여기에이

$model=$this->loadModel($id); 
$youTubevideos=$model->YoutubeVideo; 

등의 사용 관계를 사용할 수 있습니다 actionUpdate에

public function relations() 
{ 
    // NOTE: you may need to adjust the relation name and the related 
    // class name for the relations automatically generated below. 
    return array(
     'competitions' => array(self::HAS_MANY, 'Competition', 'movie_id'), 
     'studio' => array(self::BELONGS_TO, 'Studio', 'studio_id'), 
     'country' => array(self::BELONGS_TO, 'Country', 'country_id'), 
     'movieRating' => array(self::BELONGS_TO, 'MovieRating', 'movie_rating_id'), 
     'mapPin' => array(self::BELONGS_TO, 'MapPin', 'map_pin_id'), 
     'twitterFeeds' => array(self::HAS_MANY, 'TwitterFeed', 'movie_id'), 
     'YoutubeVideo' => array(self::HAS_MANY, 'YoutubeVideo', 'movie_id'), 
    ); 
} 
+0

어떻게 데이터를 표시하고 싶습니까? 자세히 표시하고 싶습니까? –

+0

CActiveForm이 – user3355603

+0

으로 설정되었습니다. 동영상 모델 –

답변

1

는 YouTube 동영상은 model.It에서 같은 관계 이름은 당신에게 모든 YouTube 동영상을 가져올 것입니다 특정 영화와 관련된 활동 기록. 이제 실제로 당신이 좋아하는 어떤 일을 에코 할 수 위의 에코 문에서

foreach($youTubeVideos as $video) 
{ 
echo $video->name; 
} 

같은 모델의 각 값을 표시하도록 뷰를 사용 foreach 루프에서 다음

$this->render('update',array(
     'model'=>$model, 
     'modelYoutubeVideo'=>$modelYoutubeVideo, 
     'modelTwitterFeed'=> $modelTwitterFeed, 
     'youTubeVideos'=>$youTubeVideos, 
    )); 

처럼보기로이 배열을 전달 CdetailView 위젯 또는 반복적으로 원하는 모든 것.

+0

훌륭하게 들리네. 지금 시험해보고 병이 들러 !! !! 다시 고마워요 – user3355603

+0

오케이, 천만에. –

+0

@ user3355603 시도해 보셨습니까? –