CI + JSON + FullCalendar |
[eluser]austintbiggs[/eluser]
I'm currently trying to create a JSON feed for FullCalendar using CI. I currently have a working example, but the output doesn't get imported into the calendar. Anyone have any ideas? I've been stuck on this for almost 3 days now.. In my controller Code: function json() In my model Code: function jsonEvents () In my view Code: <?php foreach($events->result() as $entry): ?> The corresponding JSON Code: {"id":"24242","title":"sdfsdfsdfsdf","start":"2011-05-05 13:00:53","allDay":false,"end":"2011-05-06 17:00:19"} The calendar setup Code: //Fullcalendar
[eluser]cahva[/eluser]
I'm not 100% sure but I think the error is how you output the json separately. I think it should be more like this: Code: <?php BTW, I think you should just build the json in the model and print it out in the controller. IMHO theres no need to use a view that is a pure PHP script.
[eluser]austintbiggs[/eluser]
That works! Thanks so much! This has been quite the headache, and also I thought it should be in a model, but I assumed it needs to be in the view, so that when the javascript loads that url it will be able to read the json, otherwise what link would I load for the JS?
[eluser]cahva[/eluser]
Ehm.. Its the same link than before. The only difference is that you print the json straight from controller and do not use view. For example: Model Code: function jsonEvents () controller Code: function json()
[eluser]Unknown[/eluser]
Hi guys, I'm using CI + Fullcalendar but when I'm trying to display events from my database it doesn't work. I'dont understand why I'm a begginer.. Please help me! This is my controler: [code] public function consulter($page = 'AFFICHAGE') { $this->config->set_item('language', 'fr'); $data['title'] = ucfirst($page); $this->load->model('events_model'); $this->load->view('templates/header',$data);//This is just the header $this->load->view('templates/affichage'); echo $this->events_model->get_reservation(); } My model: public function get_reservation() { $this->load->helper('url'); $query = $this->db->query("SELECT a.reservation_id as id, b.typeEvent_desc as title , a.reservation_dateDebut as start, a.reservation_dateFin as end FROM obois_reservation a, obois_event_type b WHERE a.eventType_id = b.eventType_id"); return json_encode($query->result_array()); } My view: <head> [removed] $(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, editable: true, weekends: false, defaultView: 'agendaWeek', minTime: 8, maxTime: 17, allDaySlot: false, allDayDefault: false, eventSources: [ { url: "<?php echo base_url().'/index.php/consulter';?>", color: 'yellow', // an option! textColor: 'black' // an option! } ] }); }); [removed] <style type='text/css'> #bodycalendar { margin-top: 40px; text-align: center; font-size: 14px; font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; } #loading { position: absolute; top: 5px; right: 5px; } #calendar { width: 750px; margin: 0 auto; } </style> </head> <body> <div id='loading'>loading...</div> <div id='bodycalendar'> </body> </html> I will appreaciate somebody's help I've followed this forum step by step but still it doesn't :down: |
Welcome Guest, Not a member yet? Register Sign In |