Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
calendar json request
  • Hi, I'm willing to use the Fullcalendar jquery script To be using this I need to pass a json request.
    I found the following post here on fuelphp: http://fuelphp.com/forums/topics/view/7045 But it says to extend my controller with Controller_Rest. Problem is I already extended it with the Admin controller.
    Isn't there another way or has anyone been able to use the fullcalendar script with mysql in fuelphp?
    Kind regards
    Peter
  • You can use it without Controller_Rest, I used it, but as advised by Wan_Wizard in linked topic it's ideally you extend Controller_Rest wich allows you easy JSON (or csv, xml, ...) output. Here is how I have used it without exteding Controller_Rest This is my upload controller for uploading files in admin section. It is used together with JQuery http://www.uploadify.com/ script
    class Controller_Admin_Upload extends Controller_Admin {
       public function action_index()
       {
          $this->auto_render = false;
          if (Upload::is_valid() && Input::is_ajax())
          {
             /*** upload file processing here ***/
    
             echo json_encode(array('formhtml'=>$html, 'image'=>$image));
          }
          else
          {
             // exit with fail
             exit('upload_err');
          }
       }
    }
    
  • So as the event I should write something like:
    $(document).ready(function() {
       $('#calendar').fullCalendar({
        editable: false,
        url: true,
        events: 'admin/events/index'
       })
    
      });
    

    This is my class as of now, but no json is being generated:
    class Controller_Admin_Events extends Controller_Admin
    {
    
     public function action_index()
     {
      $events = Model_Event::find('all');
      $data['events'] = $events;
      echo json_encode($events);
      print_r($events);
      $this->template->title = "Events";
      $this->template->content = View::forge('admin/events/index', $data);
    
     }
    

    The print_r does give me something but not the json.
  • You are doing something strange here in your Admin_events controller. First you are outputting JSON decoded string by using echo json_decode... then you are printing out $events ORM object which wound produce anything good, and then you are setting view to your template controller... What do you want to do here? I would say your calendar script needs to to make an AJAX request and expects some kind of JSON result? In this case do something similar as I did above with my upload controller.
  • Oh well the point is to keep the usual:
    class Controller_Admin_Events extends Controller_Admin
    {
    
     public function action_index()
     {
      $events = Model_Event::find('all');
      $data['events'] = $events;
      $this->template->title = "Events";
      $this->template->content = View::forge('admin/events/index', $data);
    
     }
    

    So I can populate my table in my view and to add the calendar underneath.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion