douken1726 2015-06-19 08:54
浏览 25
已采纳

如何在codeigniter的控制器中拆分字符串?

I am using codeigniter framework. I am getting the date from the view.i want to send them into 2 fields. like "2016-06-19" to one field and "2015-06" into another field. How can i get it done?? If anyone has an idea it would help me.

Here is my controller function.

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);
    }

date is my original date. it should be like "2015-06-19". date_half is my other date field. it should be like "2015-06"

  • 写回答

1条回答 默认 最新

  • drxzpo70788179614 2015-06-19 08:56
    关注

    It is more general PHP question then CI question. I would do it by date and strtotime functions.

    $splitted = date('Y-m', strtotime($this->input->post('date',TRUE)));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line