Yii implements the document list top-down function example, yii article list
This article describes how to implement the document list top-up function of Yii. We will share this with you for your reference. The details are as follows:
My understanding: First click to get the current ID. The model layer queries all sort fields, traverses the data, obtains the maximum value, modifies the data, and replaces the data.
:
Model layer:
// Display the list public function lists1 () {$ arr = Yii: $ app-> db-> createCommand ("select * from acticle join type on type. t_id = acticle. t_id order by sort desc ")-> queryall (); return $ arr;} // top public function top () {$ arr = $ this: find () -> select ("sort")-> asArray ()-> all (); // print_r ($ arr); die; $ rows = array (); foreach ($ arr as $ key => $ v) {$ rows [] = $ v ['sort '];} $ max = array_search (max ($ rows ), $ rows); return intval ($ rows [$ max] + 1);} // modify the data public function update1 ($ sort, $ acticle_id) {$ arr = Yii :: $ app-> db-> createCommand ()-> update ("acticle", ['sort '=> $ sort], ['acticle _ id' => $ acticle_id]); if ($ arr-> execute () {return 1 ;}else {return 2 ;}}
Controller:
// Set public function actionTopq () {$ acticle_id =$ _ GET ['id']; // echo $ acticle_id; die; // obtain the maximum sort $ model = new Acticle (); $ sort = $ model-> top (); // modify the data $ row = $ model-> update1 ($ sort, $ acticle_id); // echo $ row; die; if ($ row = 1) {// replace data, top $ res1 = $ model-> lists1 (); $ art = new Articles (); $ res6 = $ art-> get_right ($ res1, 5); return $ res6;} else {return false ;}}
View layer:
<! -- Article list --> <div class = "r_230_ B ma_b8" style = "float: right; right: 0; line "> <div class =" news_t ">