Fullcalendar codeigniter 1.7.2

时间:2012-12-10 12:24:43

标签: php codeigniter fullcalendar

我有一个使用fullcalendar jQuery的日历事件,我将在codeigniter 1.7.2中实现

当我实现这样的函数fullcalendar getEvenByCategory时,甚至根本不会出现

这是我的控制器[kalender.php]

function json_kategori($id) {
    header("Content-Type: application/json");
    echo $this->MKalender->jsonEventsByKategori();
}

function kategori($id) {
    $query = $this->db->query("
            SELECT
                COUNT(*) as jml from kalender
            WHERE
                `IDKategori` = '$id'
            ");
    foreach ($query->result() as $row) {
        $row = $row->jml;
    }
    $config['base_url'] = base_url() . 'kalender/kategori/' . $id . '/';
    $config['total_rows'] = $row;
    $config['per_page'] = '4';
    $config['uri_segment'] = 4;
    $config['first_link'] = 'Awal';
    $config['last_link'] = 'Akhir';
    $config['next_link'] = 'Selanjutnya';
    $config['prev_link'] = 'Sebelumnya';
    $this->pagination->initialize($config);
    $data['kalender'] = $this->MKalender->getAllKalenderByKategori($id,
                    $config['per_page'], $this->uri->segment(4));

    $data['kategori'] = $this->MKategoriKalender->getKategori($id);
    $data['title'] = $data['kategori']['kategori'];
    $data['main'] = 'kalender/kalender_kategori';
    $this->load->vars($data);
    $this->load->view('layout/template');
}

这是我的模特[mkalender.php]

function jsonEventsByKategori($catid) {
    $sql = "
        SELECT
                *
        FROM
                kalender
        WHERE
                IDKategori = $catid
        ORDER BY
                TanggalMulai";
    $query = $this->db->query($sql);
    // echo $sql;
    return $query->result_array();
    $jsonevents = array();
    foreach ($query as $entry) {
        $jsonevents[] = array(
            'id' => $entry->IDKalender,
            'start' => $entry->TanggalMulai,
            'end' => $entry->TanggalAkhir,
            'title' => $entry->judul,
            'body' => $entry->konten,
            'multi' => 0,
            'allDay' => false,
            'extension_id' => 2
        );
    }
    return json_encode($jsonevents);
}

在我看来[kalender / kalender_kategori.php]

<script type='text/javascript'>
$(document).ready(function() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    $('#calendar').fullCalendar({
        firstDay:'1',
        theme:true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        editable: true,
        events: '<?= base_url(); ?>kalender/json_kategori'
    });
});</script>

<div id="main"><div id='calendar'></div></div>

所以我的问题是,模型中的应用程序代码如何按类别事件显示日历事件?

1 个答案:

答案 0 :(得分:0)

1)你错过了一个叫jsonEventsByKategori的paremeter。

function json_kategori($id) {
  header("Content-Type: application/json");
   echo $this->MKalender->jsonEventsByKategori(jsonEventsByKategori); //here
}

2)在你的模型中,因为你已经返回了result_array .... jsonevents[]部分将不会执行...所以你可以在模型中返回result_array()并执行foreach循环控制器...