I want to display a timestamp value catched from DB by using a php function date() to properly format my date time.
But the question is – could it be done before passing it to the view file ?
I want to keep my view file as clean as possible concerning php functions inside a view file.
Retrieved items from a database by using /models/content_model.php:
function getPages($per_page){
$this->db->order_by('id', 'desc');
$query = $this->db->get('content', $per_page, $this->uri->segment(3));
return $query->result();
}
Then, it’s processed by controller /controllers/content.php:
...
// Get data
$componentData['results'] = $this->content_model->getPages(5);
...
And displaying results in views/content/home.php:
<?php
<?php foreach($results as $item):?>
echo $item->date_created;
<?php endforeach;?>
?>
Will output a date (type timestamp in DB) something like this: 2011-08-14 18:34:04
Instead of using a date() function inside of a view file views/content/home.php, i want to process it through date() function outside of the view, not sure if it should be done in model or controller.
Any suggestions ?
You can do it in controller class. At first make a private function name DateProcess and send the query result and process the date as you want. Then you can send the process data to view file.