/** * Lists all models. */ public function actionIndex() { $dataProvider = new CActiveDataProvider('Project'); Yii::app()->clientScript->registerLinkTag('alternate', 'application/rss+xml', $this->createUrl('comment/feed')); //get the latest system message to display based on the update_time column $sysMessage = SysMessage::model()->find(array('order' => 't.update_time DESC')); if ($sysMessage != null) { $message = $sysMessage->message; } else { $message = null; } $this->render('index', array('dataProvider' => $dataProvider, 'sysMessage' => $message)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. */ public function loadModel() { if ($this->_model === null) { if (isset($_GET['id'])) { $this->_model = SysMessage::model()->findbyPk($_GET['id']); } if ($this->_model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } } return $this->_model; }
/** * Retrieves the most recent system message. * @return SysMessage the AR instance representing the latest system message. */ public static function getLatest() { //see if it is in the cache, if so, just return it if (($cache = Yii::app()->cache) !== null) { $key = 'TrackStar.ProjectListing.SysMessage'; if (($sysMessage = $cache->get($key)) !== false) { return $sysMessage; } } //The system message was either not found in the cache, or //there is no cache component defined for the application //retrieve the system message from the database $sysMessage = SysMessage::model()->find(array('order' => 't.update_time DESC')); if ($sysMessage != null) { //a valid message was found. Store it in cache for future retrievals if (isset($key)) { //$cache->set($key,$sysMessage,300); $cache->set($key, $sysMessage, 0, new CDbCacheDependency('select id from tbl_sys_message order by update_time desc')); } return $sysMessage; } else { return null; } }
public function testGetLatest() { $message = SysMessage::getLatest(); $this->assertTrue($message instanceof SysMessage); }