format() public method

Return locale-aware formatted string
public format ( ) : string
return string
Example #1
0
 public function __toString()
 {
     return parent::format($this);
 }
Example #2
0
 /**
  * display a single post
  * @param \Base $f3
  * @param array $params
  */
 public function getSingle(\Base $f3, $params)
 {
     $this->response->data['SUBPART'] = 'post_single.html';
     $addQuery = '';
     if ($this->response instanceof \View\Backend) {
         $this->initBackend();
     } else {
         // only show published posts on the frontend
         $addQuery = ' and publish_date <= ? and published = ?';
     }
     // show only approved comments in the next query
     $this->resource->filter('comments', array('approved = ?', 1));
     // select a post by its ID
     if (isset($params['id'])) {
         $this->resource->load(array('_id = ?' . $addQuery, $params['id'], date('Y-m-d'), true));
     } elseif (isset($params['slug'])) {
         $this->resource->load(array('slug = ?' . $addQuery, $params['slug'], date('Y-m-d'), true));
     }
     if ($this->response instanceof \View\Backend) {
         $data = $this->resource->cast(null, 0);
         if (!$this->resource->dry()) {
             $tags = $this->resource->tags;
             if ($tags) {
                 $tags = implode(',', $tags->getAll('title'));
             }
             $data['tags'] = $tags;
         }
         $data['publish_date'] = $f3->format('{0,date}', !empty($data['publish_date']) ? strtotime($data['publish_date']) : time());
         // the model object itself, for getting relations etc.
         $this->response->data['post'] = $this->resource;
         // the prepared form data, processed by FooForms
         $this->response->data['POST'] = $data;
     } else {
         if ($this->resource->dry()) {
             $f3->error(404, 'Post not found');
         }
         // copy whole post model, to be able to fetch relations
         // on the fly from within the template, if we need them
         $this->response->data['post'] = $this->resource;
     }
 }