Question: How to sort the YII framework

Source: Internet
Author: User
{Code ...} $ criteria-& amp; gt; order & #039; iddesc & #039; I know, but I can only sort $ product_category, how can I sort $ products? Thank you!
public function actionIndex($id)    {        $this->pageTitle = Yii::t('zh_CN', 'PAGE_TITLE_PRODUCT');        $current_product_category_model = ProductCategory::model()->findByPk($id);        $criteria = new CDbCriteria();        $criteria->limit = 5;        $product_category = ProductCategory::model()->findAll($criteria);        $product_sub_category = ProductSubCategory::model()->findAll('product_category_id=:product_category_id', array(':product_category_id' => $id));        $products = Product::model()->findAll('product_status="online" AND product_category_id=:product_category_id', array(':product_category_id' => $id));        $this->render("index", array(            "products" => $products,            "current_product_category_model" => $current_product_category_model,            "product_category" => $product_category,            "product_sub_category" => $product_sub_category,        ));    }

$ Criteria-> order = 'id desc '; I know, but I can only sort $ product_category. How can I sort $ products? Thank you!

Reply content:
public function actionIndex($id)    {        $this->pageTitle = Yii::t('zh_CN', 'PAGE_TITLE_PRODUCT');        $current_product_category_model = ProductCategory::model()->findByPk($id);        $criteria = new CDbCriteria();        $criteria->limit = 5;        $product_category = ProductCategory::model()->findAll($criteria);        $product_sub_category = ProductSubCategory::model()->findAll('product_category_id=:product_category_id', array(':product_category_id' => $id));        $products = Product::model()->findAll('product_status="online" AND product_category_id=:product_category_id', array(':product_category_id' => $id));        $this->render("index", array(            "products" => $products,            "current_product_category_model" => $current_product_category_model,            "product_category" => $product_category,            "product_sub_category" => $product_sub_category,        ));    }

$ Criteria-> order = 'id desc '; I know, but I can only sort $ product_category. How can I sort $ products? Thank you!

Brother, you will$product_categorySorted, then you set$product_categorySet the sorted code$productsIsn't it oracle?

 $products = Product::model()->findAll(new CDbCriteria(array(      "condition" => 'product_status="online" AND product_category_id=:product_category_id',      "order" => "id desc",      "params" => array(':product_category_id' => $id)   )));

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.