Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter-在将检索到的值发送到视图之前,对其进行处理_Php_Mysql_Database_Codeigniter 2 - Fatal编程技术网

Php Codeigniter-在将检索到的值发送到视图之前,对其进行处理

Php Codeigniter-在将检索到的值发送到视图之前,对其进行处理,php,mysql,database,codeigniter-2,Php,Mysql,Database,Codeigniter 2,我想通过使用php函数date()来正确设置日期时间的格式,显示从DB捕获的时间戳值 但问题是-在将其传递到视图文件之前是否可以完成此操作关于视图文件中的php函数,我希望保持视图文件尽可能干净 使用/models/content\u model.php从数据库检索项目: function getPages($per_page){ $this->db->order_by('id', 'desc'); $query = $this->db->get('con

我想通过使用php函数
date()
来正确设置日期时间的格式,显示从DB捕获的时间戳值

但问题是-在将其传递到视图文件之前是否可以完成此操作
关于视图文件中的php函数,我希望保持视图文件尽可能干净

使用
/models/content\u 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();
}
...
// Get data
$componentData['results'] = $this->content_model->getPages(5);
...
<?php
    <?php foreach($results as $item):?>
        echo $item->date_created;
     <?php endforeach;?>
?>
然后,它由controller
/controllers/content.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();
}
...
// Get data
$componentData['results'] = $this->content_model->getPages(5);
...
<?php
    <?php foreach($results as $item):?>
        echo $item->date_created;
     <?php endforeach;?>
?>
并在
视图/content/home.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();
}
...
// Get data
$componentData['results'] = $this->content_model->getPages(5);
...
<?php
    <?php foreach($results as $item):?>
        echo $item->date_created;
     <?php endforeach;?>
?>

echo$项目->创建日期;
?>
将输出一个日期(以DB为单位键入时间戳),如下所示:
2011-08-14 18:34:04

我不想在视图文件
views/content/home.php
中使用
date()
函数,而是想在视图之外通过
date()
函数来处理它,不确定是在model还是controller中完成


有什么建议吗?

您可以在控制器类中执行。首先,创建一个私有函数名DateProcess并发送查询结果,然后根据需要处理日期。然后你可以将过程数据发送到查看文件。

omg,我真的是个编程高手,没法得到它。My
$componentData['results']
包含检索到的项的数组。我制作了一个处理日期的函数
dateProcess($date)
,但如何将它与数组
$componentData['results']
中已经检索到的结果混合使用呢。谢谢