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

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:


 
' maxlength="30" aria-invalid="false">


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!