0

我有一个使用 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>

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

4

1 回答 1

0

1)你错过了一个 jsonEventsByKategori被调用的参数。

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

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

于 2012-12-10T13:07:19.620 回答