yii data processing help
WWK
WWK 2019-07-15 18:48:35
0
0
1035

There are two fields in the database vod table:



##vod_play:

qq$$$iqiyi$$$sohu$$$youku$$$mgtv



vod_url:


1$http://v.qq.com/x/cover/llws99784lrtpz7/g003189nkf3.html
2$http://v.qq.com/x/cover/llws99784lrtpz7/f0031cijuxc.html
$$$http://www.iqiyi.com/v_19rse7ldt0.html
2$http://www.iqiyi.com/v_19rse7mbz0.html
$$$http://tv.sohu.com/v/MjAxOTA2MjUvbjYwMDczMDI0MS5zaHRtbA==.html
2$http://tv.sohu.com/v/MjAxOTA2MjUvbjYwMDczMDI0My5zaHRtbA==.html
$$$http://v.youku.com/v_show/id_XNDI0Mjg3NDcyOA==.html
2$http://v.youku.com/v_show/id_XNDI0Mjg3NDczMg==.html
$$$http://www.mgtv.com/b/330256/5878154.html
2$http://www.mgtv.com/b/330256/5878408.html


I want to display them in groups in the form, qq corresponds The playback address of qq and iqiyi correspond to the playback address of iqiyi. . . :

QQ截图20190715183259.png


The currently implemented method is as follows:


1, in model Create a new method in the class to split the string and reassemble it into an array;


public function getPlaylist(){
$datas['vod_play'] =  explode('$$$', $this->vod_play);
$datas['url'] = explode('$$$', $this->vod_url);
$playlist=[];
if (is_array($datas)) {
    foreach ($datas as $key => $value) {
        foreach ($value as $k => $v) {
            $playlist[$k][$key] = $datas[$key][$k];
        }
    }
    return $playlist;
}
}


Second, pass the array to the view in the controller:



public function actionUpdate($id)
{
$model = $this->findModel($id);
$playlists= $model->getPlaylist();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
    return $this->redirect(['view', 'id' => $model->vod_id]);
}
return $this->render('update', [
    'model' => $model,
    'playlists'=>$playlists,
]);
}


##Three, loop this array in the view:


<?php foreach ($playlists as $playlist):?>
<div class="form-group field-player">
<label class="control-label" for="player">播放器</label>
<input type="text" id="player" class="form-control" name="player[]" value='<?php echo $playlist['vod_play'];?>' maxlength="30" aria-invalid="false">
<div class="help-block"></div>
</div>
<div class="form-group field-url">
<label class="control-label" for="url">播放地址</label>
<textarea id="ffvod-vod_content" class="form-control" name="url[]" rows="12" aria-invalid="false"><?php echo $playlist['url']?></textarea>
<div class="help-block"></div>
</div>
<?php endforeach;?>


In this way, activeform cannot be used to process the view, and a bunch of html and php have been written. The mixed code,


# is asking for help. Is there any other way to implement it? Can I use activeform in the view to handle it?


Thanks!

WWK
WWK

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template