SHOW:
|
|
- or go back to the newest paste.
| 1 | public function rules() {
| |
| 2 | return array( | |
| 3 | array('name, email, subject, message', 'required', 'message' => Yii::t('app', 'MSG_ATTRIBUTE_BLANK')),
| |
| 4 | array('email', 'email'),
| |
| 5 | array('verifyCode', 'CaptchaExtendedValidator', 'allowEmpty' => !CCaptcha::checkRequirements(), 'on' => 'fContact'),
| |
| 6 | - | array('name, email,subject,message', 'safe','lastactivity', 'on' => 'search'),
|
| 6 | + | array('name, email,subject,message,lastactivity', 'safe', 'on' => 'search'),
|
| 7 | array('name, subject, email, message, status,createdon,updatedon,verifyCode,lastactivity', 'safe'),
| |
| 8 | ); | |
| 9 | } | |
| 10 | public function relations() {
| |
| 11 | return array( | |
| 12 | 'ca' => array(self::HAS_MANY, 'ContactAction', 'contact_id'), | |
| 13 | ); | |
| 14 | } | |
| 15 | ||
| 16 | public function search() {
| |
| 17 | $criteria = new CDbCriteria; | |
| 18 | $lastactivity_sql = '(select max(date) from tbl_contact_action where contact_id=t.contact_id)'; | |
| 19 | $criteria->select = array('t.*', $lastactivity_sql . ' as lastactivity');
| |
| 20 | $criteria->addCondition('t.status<>"Deleted"');
| |
| 21 | $criteria->compare($lastactivity_sql, $this->lastactivity); | |
| 22 | $sort = new CSort; | |
| 23 | $sort->defaultOrder = array('name' => CSort::SORT_ASC);
| |
| 24 | $sort->attributes = array( | |
| 25 | 'name' => 'name', | |
| 26 | 'email' => 'email', | |
| 27 | 'status' => 'status', | |
| 28 | 'createdon' => 'createdon', | |
| 29 | 'lastactivity' => 'lastactivity', | |
| 30 | ); | |
| 31 | $sort->applyOrder($criteria); | |
| 32 | ||
| 33 | return new CActiveDataProvider($this, array( | |
| 34 | 'criteria' => $criteria, | |
| 35 | 'sort' => $sort, | |
| 36 | 'pagination' => array( | |
| 37 | 'pageSize' => Yii::app()->user->getState('contactPageSize', Yii::app()->params['RECORDPERPAGE_ADMIN']),
| |
| 38 | 'currentPage' => Yii::app()->user->getState('Contact_page', 0),
| |
| 39 | ), | |
| 40 | )); | |
| 41 | } | |
| 42 | CGRIDVIEW on display page | |
| 43 | --------------------------- | |
| 44 | <?php | |
| 45 | $this->widget('ext.selgridview.SelGridView', array(
| |
| 46 | 'id' => 'contact_grid', | |
| 47 | 'dataProvider' => $dataProvider, | |
| 48 | 'pageSizeVar' => 'contact', | |
| 49 | 'columns' => array( | |
| 50 | array( | |
| 51 | 'id' => 'autoId', | |
| 52 | 'class' => 'gridCheckBoxColumn', | |
| 53 | 'headerHtmlOptions' => array('class' => 'checkbox paracheck'),
| |
| 54 | 'htmlOptions' => array('class' => 'checkbox paracheck'),
| |
| 55 | ), | |
| 56 | array( | |
| 57 | 'header' => 'Last Activity', | |
| 58 | 'class' => 'gridDataColumn', | |
| 59 | 'name' => 'lastactivity', | |
| 60 | 'value' => 'CommonFunctions::formatDateTime($data->lastactivity)', | |
| 61 | 'htmlOptions' => array('class' => 'maincell'),
| |
| 62 | 'headerHtmlOptions' => array('title' => Yii::t('app', 'LBL_LIST_SORT_DATE_TITLE'))
| |
| 63 | ), | |
| 64 | ), | |
| 65 | )); | |
| 66 | ?> | |
| 67 | ||
| 68 | ||
| 69 | Error | |
| 70 | ------ | |
| 71 | - | Property "CSafeValidator.0" is not defined. |
| 71 | + | 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 |