我想使用codeigniter进行全日历,但是以某种方式遇到此错误

时间:2019-05-13 17:04:40

标签: codeigniter fullcalendar

我遇到此错误。如果您知道解决方法,请帮助我

  

严重性:错误   消息:调用未定义的函数form_open()   文件名:views / index.php   行号:33

  1. index.php(查看)

                 日历显示

    class Calendar extends CI_Controller {
    
    public function __construct() {
        parent::__construct();
        $this->load->model("calendar_model");
    }
    
    public function index()
    {
        $this->load->helper('url');
        $this->load->view('index', array());
    }
    
     public function get_events()
     {
         // Our Start and End Dates
         $start = $this->input->get('start');
         $end = $this->input->get('end');
    
         $startdt = new DateTime('now'); // setup a local datetime
         $startdt->setTimestamp($start); // Set the date based on timestamp
         $start_format = $startdt->format('Y-m-d H:i:s');
    
         $enddt = new DateTime('now'); // setup a local datetime
         $enddt->setTimestamp($end); // Set the date based on timestamp
         $end_format = $enddt->format('Y-m-d H:i:s');
    
         $events = $this->calendar_model->get_events($start_format, $end_format);
    
         $data_events = array();
    
         foreach($events->result() as $r) {
    
             $data_events[] = array(
                 "id" => $r->ID,
                 "title" => $r->title,
                 "description" => $r->description,
                 "end" => $r->end,
                 "start" => $r->start
             );
         }
    
         echo json_encode(array("events" => $data_events));
         exit();
     }
    
     public function add_event() 
    {
        /* Our calendar data */
        $name = $this->input->post("name", TRUE);
        $desc = $this->input->post("description", TRUE);
        $start_date = $this->input->post("start_date", TRUE);
        $end_date = $this->input->post("end_date", TRUE);
    
        if(!empty($start_date)) {
           $sd = DateTime::createFromFormat("Y/m/d H:i", $start_date);
           $start_date = $sd->format('Y-m-d H:i:s');
           $start_date_timestamp = $sd->getTimestamp();
        } else {
           $start_date = date("Y-m-d H:i:s", time());
           $start_date_timestamp = time();
        }
    
        if(!empty($end_date)) {
           $ed = DateTime::createFromFormat("Y/m/d H:i", $end_date);
           $end_date = $ed->format('Y-m-d H:i:s');
           $end_date_timestamp = $ed->getTimestamp();
        } else {
           $end_date = date("Y-m-d H:i:s", time());
           $end_date_timestamp = time();
        }
    
        $this->calendar_model->add_event(array(
           "title" => $name,
           "description" => $desc,
           "start" => $start_date,
           "end" => $end_date
           )
        );
    
        redirect(site_url("calendar"));
    }
    

  2. Calendar.php(控制器)

    class Calendar_model extends CI_Model {
    
    public function get_events($start, $end){
    
        return $this->db->where("start >=", $start)->where("end <=", $end)->get('calendar_events');
    }
    
    public function add_event($data)
    {
        $this->db->insert('calendar_events', $data);
    }
    
    public function get_event($id)
    {
        return $this->db->where("ID", $id)->get('calendar_events');
    }
    
    public function update_event($id, $data)
    {
        $this->db->where("ID", $id)->update('calendar_events', $data);
    }
    
    public function delete_event($id)
    {
        $this->db->where("ID", $id)->delete('calendar_events');
    }
    

    }

  3. Calendar_model.php(模型)

    output_file

    }

1 个答案:

答案 0 :(得分:0)

在HTML中,似乎存在标记问题。但是无论如何,您都需要确保将表单助手和URL助手都加载到要使用的函数中。

public function index()
{
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->view('index', array());
}