Skip to content

Instantly share code, notes, and snippets.

@jamband
Last active December 29, 2015 17:12
Show Gist options
  • Save jamband/1471371 to your computer and use it in GitHub Desktop.
Save jamband/1471371 to your computer and use it in GitHub Desktop.
Yii Framework: How to specify a column alias.
<?php
class Forum extends ActiveRecord
{
public $max_number;
public $max_create_time;
...
public function getLatestAll()
{
$c = new CDbCriteria();
$c->with = array('topic');
$c->select = 'MAX(t.number) AS max_number, MAX(t.create_time) AS max_create_time';
$c->group = 't.topic_id';
$c->order = 'mac_create_time DESC';
return $this->findAll($c);
}
...
<?php foreach ($models as $model): ?>
<?php echo CHtml::encode($model->max_createtime); ?>
<?php echo CHtml::encode($model->max_number); ?>
...
<?php endforeach; ?>
@bankchart
Copy link

thank you. ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment