Yii implements the document list top-down function example, yii article list

Source: Internet
Author: User

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 "> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.