Yii Csort With ActiveRecord

controller 部份

$sort->attributes= array(
    'product.id'=>'productId',
    'product.name'=>'productName',
    'category.name'=>'categoryName',
    'brand.name' => 'brandName',
);

/*
$sort->attributes= array(
    'model中的alias.欄位'=>'網址顯示的Alias',
);
*/

view 部份

< ?php echo $sort->link('product.id','編號'); ?>
//< ?php echo $sort->link('table.name','網頁顯示的名稱'); ?>

model 部份
記得把 relations中的 alias 設好

如下

  /**
   * @return array relational rules.
   */
  public function relations()
  {
    return array(
      'brand'=>array(self::BELONGS_TO,'brand','brand_id', 'alias'=>'brand'),
      'category'=>array(self::BELONGS_TO,'category','category_id', 'alias'=>'category'),
      'series'=>array(self::BELONGS_TO,'series','series_id','alias'=>'series'),
    );
  }

About johnpupu

..........
This entry was posted in program and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word