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)));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来