Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function rules() {
- return array(
- array('name, email, subject, message', 'required', 'message' => Yii::t('app', 'MSG_ATTRIBUTE_BLANK')),
- array('email', 'email'),
- array('verifyCode', 'CaptchaExtendedValidator', 'allowEmpty' => !CCaptcha::checkRequirements(), 'on' => 'fContact'),
- array('name, email,subject,message,lastactivity', 'safe', 'on' => 'search'),
- array('name, subject, email, message, status,createdon,updatedon,verifyCode,lastactivity', 'safe'),
- );
- }
- public function relations() {
- return array(
- 'ca' => array(self::HAS_MANY, 'ContactAction', 'contact_id'),
- );
- }
- public function search() {
- $criteria = new CDbCriteria;
- $lastactivity_sql = '(select max(date) from tbl_contact_action where contact_id=t.contact_id)';
- $criteria->select = array('t.*', $lastactivity_sql . ' as lastactivity');
- $criteria->addCondition('t.status<>"Deleted"');
- $criteria->compare($lastactivity_sql, $this->lastactivity);
- $sort = new CSort;
- $sort->defaultOrder = array('name' => CSort::SORT_ASC);
- $sort->attributes = array(
- 'name' => 'name',
- 'email' => 'email',
- 'status' => 'status',
- 'createdon' => 'createdon',
- 'lastactivity' => 'lastactivity',
- );
- $sort->applyOrder($criteria);
- return new CActiveDataProvider($this, array(
- 'criteria' => $criteria,
- 'sort' => $sort,
- 'pagination' => array(
- 'pageSize' => Yii::app()->user->getState('contactPageSize', Yii::app()->params['RECORDPERPAGE_ADMIN']),
- 'currentPage' => Yii::app()->user->getState('Contact_page', 0),
- ),
- ));
- }
- CGRIDVIEW on display page
- ---------------------------
- <?php
- $this->widget('ext.selgridview.SelGridView', array(
- 'id' => 'contact_grid',
- 'dataProvider' => $dataProvider,
- 'pageSizeVar' => 'contact',
- 'columns' => array(
- array(
- 'id' => 'autoId',
- 'class' => 'gridCheckBoxColumn',
- 'headerHtmlOptions' => array('class' => 'checkbox paracheck'),
- 'htmlOptions' => array('class' => 'checkbox paracheck'),
- ),
- array(
- 'header' => 'Last Activity',
- 'class' => 'gridDataColumn',
- 'name' => 'lastactivity',
- 'value' => 'CommonFunctions::formatDateTime($data->lastactivity)',
- 'htmlOptions' => array('class' => 'maincell'),
- 'headerHtmlOptions' => array('title' => Yii::t('app', 'LBL_LIST_SORT_DATE_TITLE'))
- ),
- ),
- ));
- ?>
- Error
- ------
- CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't.lastactivity' in 'order clause'. The SQL statement executed was: SELECT t.*, (select max(date) from tbl_contact_action where contact_id=t.contact_id) as lastactivity FROM `tbl_contact` `t` WHERE t.status<>"Deleted" ORDER BY lastactivity, `t`.`lastactivity` LIMIT 10
Advertisement
Add Comment
Please, Sign In to add comment