按类别codeigniter 1.7.2获取json事件

时间:2012-12-10 07:55:34

标签: php jquery json codeigniter

我希望按类别json获得日历活动。

这是我在控制器中的代码

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

这是我在模型中的代码

function jsonEventsByKategori($catid) {
    $this->db->order_by('TanggalMulai', 'desc');
    $this->db->where("IDKategori", $catid);
    $events = $this->db->get('kalender')->result();
    $jsonevents = array();
    foreach ($events 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);
}

这是我在视图中的代码[load json calender event]

$(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'
    });
});

数据库表名是,kalender和kalender_kategori

我的kalender SQL是

CREATE TABLE `kalender`(
`IDKalender` INT(10)UNSIGNED NOT NULL AUTO_INCREMENT,
`IDKategori` INT(11)NOT NULL,
`TanggalMulai` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`TanggalAkhir` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`judul` VARCHAR(100)NOT NULL,
`konten` text NOT NULL,
`user` VARCHAR(25)NOT NULL DEFAULT 'anonimous',
PRIMARY KEY(`IDKalender`))ENGINE = MyISAM AUTO_INCREMENT = 3 DEFAULT CHARSET = latin1;

我的kalender_kategory SQL是

CREATE TABLE `kalender_kategori`(
`IDKategori` TINYINT(11)NOT NULL AUTO_INCREMENT,
`kategori` VARCHAR(60)COLLATE latin1_general_ci NOT NULL DEFAULT '',
`deskripsi` text COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY(`IDKategori`))ENGINE = MyISAM AUTO_INCREMENT = 9 DEFAULT CHARSET = latin1 COLLATE = latin1_general_ci;

如果上面的代码错了?如果有一个,哪个是错的?如果我想采取甚至只存在于特定事件类别。

0 个答案:

没有答案