如何在代码点火器的控制器中拆分字符串


How to split a string in the controller of codeigniter?

我正在使用codeigniter框架。我正在从视图中获取日期。我想将它们发送到 2 个字段中。像"2016-06-19"到一个字段,"2015-06"到另一个字段。我怎样才能完成它??如果有人有想法,它会帮助我。

这是我的控制器功能。

function add() {
        $reservation_model = new Reservation_model();
        $reservation_service = new Reservation_service();
        $newDate=$this->input->post('date',TRUE);
        $splitted= split("-", $newDate, 1);
        $reservation_model->set_date(trim($this->input->post('date',TRUE)));
        $reservation_model->set_date_half($splitted);
        $reservation_model->set_title(trim($this->input->post('selected_hall', TRUE)));
        $reservation_model->set_type(trim($this->input->post('selected_time', TRUE)));
        $reservation_model->set_description(trim($this->input->post('name', TRUE)));
        $reservation_model->set_advanced_payment_status(trim($this->input->post('optionsRadios', TRUE)));
        //$reservation_model->set_advanced_payment_status(trim($this->input->post('no', TRUE)));
        $reservation_model->set_paid_amount(trim($this->input->post('paid_amount', TRUE)));
        $reservation_model->set_fax(trim($this->input->post('fax', TRUE)));
        $reservation_model->set_telephone_number(trim($this->input->post('telephone', TRUE)));
        $reservation_model->set_address(trim($this->input->post('address', TRUE)));
        $reservation_model->set_menu_no(trim($this->input->post('selected_menu_number', TRUE)));
        $reservation_model->set_menu_price_per_plate(trim($this->input->post('menu_price', TRUE)));
        $reservation_model->set_is_deleted('0');
        //$this->db->last_query();

        echo $reservation_service->add_reservation($reservation_model);
    }
日期是我原来的日期。 它应该像"2015-06-19

"。 date_half是我的另一个日期字段。 它应该像"2015-06"

这是更一般的PHP问题,然后是CI问题。我会按日期和时间函数来做。

$splitted = date('Y-m', strtotime($this->input->post('date',TRUE)));