从数据库获取fullcalendar的事件详细信息(标题,开始和结束) [英] Fetch event details (title, start and end) from database for fullcalendar

查看:1848
本文介绍了从数据库获取fullcalendar的事件详细信息(标题,开始和结束)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的在搜索很多关于这个,但我还是没有得到我的问题。我创建一个日历(使用插件fullcalendar和使用codeigniter作为后端),将显示一个游览,它的具体时间跨度。因此,在这种情况下,事件的标题将是游览名称,并且在游览的持续时间,开始和结束日期将被提取。



我已经成功将数据插入到数据库,只是事件没有出现在各自的日期。



这是我到目前为止编码的内容:

Controller:Calendar.php

  function view_tours(){
$ this-> load-> model('Calendar_model');
$ tours = $ this-> Calendar_model-> getTours();
echo json_encode($ tours);
}

function add_tour(){
$ sdate = $ this-> input-> post('start_date'); // start date
$ edate = $ this-> input-> post('end_date'); // end date
if($ this-> form_validation-> run()== TRUE){// db中的列名称=>形式的名称
$ tour = array '=> $ this-> input-> post('tour_name'),
'start_date'=> date('Ym-d',strtotime($ sdate)),
' end_date'=> date('Ym-d',strtotime($ edate)),
'slots'=> $ this-> input-> post('slots'),
'rate'=> $ this-> input-> post('rate'),);
$ this-> Calendar_model-> insert_tour($ tour);
echo'success';
} else {
redirect(base_url()。'Calendar');
echoerror;
}

}

Model:Calendar_model。 php

  public function getTours(){
$ query = $ this-> db-> get('tours');
return $ query - > result_array();
}
function insert_tour($ tour){
$ this-> db-> insert('tours',$ tour);
return $ this-> db-> insert_id();
}

查看:home.php html文件)

 < div id =AddModalclass =modal fade> 
< div class =modal-dialog>
< div class =modal-content>
< div class =modal-header>
< button type =buttonclass =closedata-dismiss =modal>< span aria-hidden =true>×< / span> < span class =sr-only> close< / span>< / button>
< h4 id =modalTitleclass =modal-title>添加游览< / h4>
< / div>
< div id =modalBodyclass =modal-body>
<?php

echo validation_errors();
?>
< form class =form-horizo​​ntalid =crud-formmethod =POSTaction =<?php echo base_url();?> Calendar / add_tour>

< div class =form-group>
< label class =col-md-4 control-labelfor =tour_name> Tour名称< / label>
< div class =col-md-4>
< input type =textclass =form-controlid =tour_namename =tour_name/>
< / div>
< / div>

< div class =form-group>
< label class =col-md-4 control-labelfor =start_date>开始日期< / label>
< div class =col-md-4>
< input type =dateclass =form-controlid =start_datename =start_date/>
< / div>
< / div>

< div class =form-group>
< label class =col-md-4 control-labelfor =end_date>结束日期< / label>
< div class =col-md-4>
< input type =dateclass =form-controlid =end_datename =end_date/>
< / div>
< / div>


< div class =form-group>
< label class =col-md-4 control-labelfor =slots>插槽< / label>
< div class =col-md-4>
< input type =textclass =form-controlid =slotsname =slots/>
< / div>
< / div>

< div class =form-group>
< label class =col-md-4 control-labelfor =rate> Rate< / label>
< div class =col-md-4>
< input type =textclass =form-controlid =ratename =rate/>
< / div>
< / div>


< div class =form-group>
< label class =col-md-4 control-labelfor =color>颜色< / label>
< div class =col-md-4>
< input id =colorname =colortype =textclass =form-control input-mdreadonly =readonly/&
< span class =help-block>点击以选择颜色< / span>
< / div>
< / div>

< button type =submitclass =btn btn-primary>添加游览< / button>
< / form>


< / div> <! - 模态体的结束 - >
< div class =modal-footer>
< button type =buttonclass =btn btn-defaultdata-dismiss =modal>关闭< / button>
< / div>
< / div>
< / div>
< / div>



我最近编辑过这个,但是不行。 我尝试使用$ .ajax选项获取数据,但是当我这样做时,日历本身不会出现。代码有什么问题?我只是ajax的初学者。

 事件:{
url:base_url +'Calendar / view_tours',
type:'POST',
data {
title:tour_name,
start:start_date,
end:end_date

},error:function (){
alert('从数据库获取错误!');
}

},//事件结束

只是粘贴了一个js的片段。我知道日历是以某种方式从数据库检索数据,因为我可以看到事件,但是,它只显示在当前日期的实时,并显示当前时间,对于所有添加的事件。我已经添加了一个工具提示,看看是否正在阅读游览名称(标题),它是。



以下是实际结果:点击查看图片



问题摘要:

1)活动不在各自的日期,实时添加的时间



提前谢谢!

解决方案

因此,您的问题似乎是您的URL返回的JSON对象具有无法识别的fullCalendar数据。所以你必须获取这样的事件:

  events:base_url +'Calendar / view_tours',

将数据库的列从 tour_id 更改为 id , / code>到开始 end_date 结束。这将创建正确的JSON对象。


I have really searched a lot about this, but I still haven't gotten through with my problem. I am creating a calendar (using the plugin fullcalendar and using codeigniter as the backend) that would display a tour and it's specific time span. So, in this case the title of the event would be the tour name, and for the duration of the tour, the start and end dates is to be fetched.

I have already succeeded with the insertion of the data to the database, it's just that the events are not appearing on their respective dates.

These are what I have coded so far:
Controller: Calendar.php

function view_tours(){ 
    $this->load->model('Calendar_model');
    $tours = $this->Calendar_model->getTours();
    echo json_encode($tours);
  }

 function add_tour(){
    $sdate = $this->input->post('start_date'); //start date
    $edate = $this->input->post('end_date'); //end date
    if($this->form_validation->run() == TRUE){ //column name in db=>name in form
            $tour = array('tour_name' => $this->input->post('tour_name'), 
                    'start_date' => date('Y-m-d', strtotime($sdate)), 
                    'end_date' => date('Y-m-d', strtotime($edate)),
                    'slots' => $this->input->post('slots'),
                    'rate' => $this->input->post('rate'),);
            $this->Calendar_model->insert_tour($tour);
            echo 'success';
    } else {
          redirect(base_url().'Calendar');
          echo "error"; 
     }

   }

Model: Calendar_model.php

public function getTours(){
    $query = $this->db->get('tours');
    return $query -> result_array();
}
function insert_tour($tour){
        $this->db->insert('tours', $tour); 
        return $this->db->insert_id();
}

View: home.php (This is the html file)

<div id="AddModal" class="modal fade">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span> <span class="sr-only">close</span></button>
                                <h4 id="modalTitle" class="modal-title"> Add a Tour </h4> 
                            </div>
                            <div id="modalBody" class="modal-body"> 
                                <?php

                                echo validation_errors();
                            ?>
                            <form class="form-horizontal" id="crud-form" method="POST" action="<?php echo base_url();?>Calendar/add_tour">

                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="tour_name">Tour Name</label>
                                    <div class="col-md-4">
                                        <input type="text" class="form-control" id="tour_name" name="tour_name"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="start_date">Start Date</label>
                                    <div class="col-md-4">
                                        <input type="date" class="form-control" id="start_date" name="start_date"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="end_date">End Date</label>
                                    <div class="col-md-4">
                                        <input type="date" class="form-control" id="end_date" name="end_date"/>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="slots">Slots</label>
                                    <div class="col-md-4">
                                        <input type="text" class="form-control" id="slots" name="slots"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="rate">Rate</label>
                                    <div class="col-md-4">
                                        <input type="text" class="form-control" id="rate" name="rate"/>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="color">Color</label>
                                    <div class="col-md-4">
                                        <input id="color" name="color" type="text" class="form-control input-md" readonly="readonly" />
                                        <span class="help-block">Click to pick a color</span>
                                    </div>
                                </div>

                                 <button type="submit" class="btn btn-primary"> Add Tour</button>
                            </form>


                            </div> <!--end of modal body-->
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            </div>
                        </div>
                    </div>
                </div>

I have recently edited this but this does not work.
JS File: main.js I have tried fetching data using the $.ajax options but when i do this, the calendar itself does not appear. What is wrong with the code? I am just a beginner with ajax.

events: {
        url: base_url+'Calendar/view_tours',
        type: 'POST',
        data{
            title: tour_name,
            start: start_date,
            end: end_date

        },error: function(){
            alert('error in fetching from database!');
        }

    }, //end of events

I just pasted a snippet of the js. I know that the calendar is "somehow" retrieving data from the database because i can see the events, BUT, it only appears on the current date in real time and shows the current time, for all events added. And i have added a tool tip to see if the tour name (title) is being read, and it is.

Here's what the actual results are: click to see image

Summary of problem:
1) Events are not in their respective dates and the time added is on realtime

Thank you in advance!

解决方案

So it seems like your problem is that the JSON object returned by your URL has unrecognizable data for fullCalendar. So you'll have to fetch events like this:

events: base_url+'Calendar/view_tours',

And change the columns of your data base from tour_id to id, tour_name to title, start_date to start and end_date to end. This will create the correct JSON object.

这篇关于从数据库获取fullcalendar的事件详细信息(标题,开始和结束)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆