Example #1
0
 /**
  * Fetches posts from database with offset and limit.
  */
 protected function getPosts($offset, $limit)
 {
     // Construts a query criteria
     $criteria = new TActiveRecordCriteria();
     $criteria->OrdersBy['create_time'] = 'desc';
     $criteria->Limit = $limit;
     $criteria->Offset = $offset;
     // query for the posts with the above criteria and with author information
     return PostRecord::finder()->withAuthor()->findAll($criteria);
 }
Example #2
0
 /**
  * Returns the post data to be editted.
  * @return PostRecord the post data to be editted.
  * @throws THttpException if the post data is not found.
  */
 protected function getPost()
 {
     // the ID of the post to be editted is passed via GET parameter 'id'
     $postID = (int) $this->Request['id'];
     // use Active Record to look for the specified post ID
     $postRecord = PostRecord::finder()->findByPk($postID);
     if ($postRecord === null) {
         throw new THttpException(500, 'Post is not found.');
     }
     return $postRecord;
 }
Example #3
0
 /**
  * Fetches the post data.
  * This method is invoked by the framework when initializing the page
  * @param mixed event parameter
  */
 public function onInit($param)
 {
     parent::onInit($param);
     // post id is passed via the 'id' GET parameter
     $postID = (int) $this->Request['id'];
     // retrieves PostRecord with author information filled in
     $this->_post = PostRecord::finder()->withAuthor()->findByPk($postID);
     if ($this->_post === null) {
         // if post id is invalid
         throw new BlogException(500, 'Unable to find the specified post.');
     }
     // set the page title as the post title
     $this->Title = $this->_post->title;
 }