我对codeigniter和MVC设计还不熟悉。我正在将旧的coldfusion MX网站转换为新的设计/布局。
目前,我需要传播查询中的下拉列表。下拉列表将是日期时间,但我希望它仅显示日期。
DROPDOWN: 2017-10-24 - > 2016-10-24 00:00:00.000
型号:
<?php
class Client_model extends CI_Model {
function __construct(){
parent::__construct();
}
function get_dates($datadate) {
$project_number = $this->session->userdata ('user_details')[0]->project_number;
$datadate = array();
$this->db->distinct();
$this->db->select('datadate');
$this->db->where('clientnumber', $project_number);
$this->db->group_by("datadate");
$this->db->order_by('datadate', 'DESC');
$query = $this->db->get('clientdata');
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row) {
$datadate[] = $row;
}
}
log_message('debug',print_r($datadate,TRUE));
return $datadate;
}
}
控制器:
<?php defined("BASEPATH") OR exit("No direct script access allowed");
class client extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index(){
$this->load->view("include/header");
$this->load->model("Client_model");
$data['datadate'] = $this->Client_model->get_dates($datadate);
$this->load->view('index', $data);
$this->load->view("include/footer");
}
}
?>
查看:
<!-- page content -->
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper settingPage">
<!-- Main content -->
<section class="content">
<!-- Default box -->
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">Select date/unit</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-12">
<div class="col-md-6 col-md-offset-1 aboutshift">
<?php echo form_dropdown('date',$datadate);?>
</div>
</div>
</div>
</div>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
调试数组。需要将(0,1,2等)更改为日期
DEBUG - 2017-10-24 11:32:16 --> Array
(
[0] => Array
(
[datadate] => 2016-10-17 00:00:00.000
)
[1] => Array
(
[datadate] => 2016-10-16 00:00:00.000
)
[2] => Array
(
[datadate] => 2016-10-15 00:00:00.000
)
)
答案 0 :(得分:0)
您需要将date()函数与strtotime()函数结合使用。
类似于
的东西date("Y-m-d", strtotime($datadate))
或者你可以在SQL中作为PrAtik Lochawala来实现。
答案 1 :(得分:0)
试试这个
function get_dates()
{
$project_number = $this->session->userdata('user_details')[0]->project_number;
$this->db->distinct();
$this->db->select('DATE(datadate)');
$this->db->where('clientnumber', $project_number);
$this->db->group_by("datadate");
$this->db->order_by('datadate', 'DESC');
$query = $this->db->get('clientdata');
$datadate = $query->result_array();
return $datadate;
}