php - 在 View 文件中可以写什么url代码来调用Laravel Controller中的函数?

标签 php laravel fullcalendar

$('#calendar').fullCalendar({
            events: JSON.parse(json_events),
            //events: [{"id":"14","title":"New Event","start":"2015-01-24T16:00:00+04:00","allDay":false}],
            utc: true,
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            editable: true,
            droppable: true, 
            slotDuration: '00:30:00',
            eventReceive: function(event){
                var title = event.title;
                var start = event.start.format("YYYY-MM-DD[T]HH:mm:SS");
                $.ajax({
                    url: 'process.php',
                    data: 'type=new&title='+title+'&startdate='+start+'&zone='+zone,
                    type: 'POST',
                    dataType: 'json',
                    success: function(response){
                        event.id = response.eventid;
                        $('#calendar').fullCalendar('updateEvent',event);
                    },
                    error: function(e){
                        console.log(e.responseText);

                    }
                });
                $('#calendar').fullCalendar('updateEvent',event);
                console.log(event);
            },

这是我在网上找到的代码,我不明白url部分。因为我使用的是Laravel,我不确定在url部分写什么。 我已经创建了一个 Controller 和模型,只是不确定如何将数据传入并存储在数据库中。

这是process.php 这个可以转换成controller和model吗?

$type = $_POST['type'];

if($type == 'new')
{
    $startdate = $_POST['startdate'].'+'.$_POST['zone'];
    $title = $_POST['title'];
    $insert = mysqli_query($con,"INSERT INTO calendar(`title`, `startdate`, `enddate`, `allDay`) VALUES('$title','$startdate','$startdate','false')");
    $lastid = mysqli_insert_id($con);
    echo json_encode(array('status'=>'success','eventid'=>$lastid));
}

if($type == 'changetitle')
{
    $eventid = $_POST['eventid'];
    $title = $_POST['title'];
    $update = mysqli_query($con,"UPDATE calendar SET title='$title' where id='$eventid'");
    if($update)
        echo json_encode(array('status'=>'success'));
    else
        echo json_encode(array('status'=>'failed'));
}

if($type == 'resetdate')
{
    $title = $_POST['title'];
    $startdate = $_POST['start'];
    $enddate = $_POST['end'];
    $eventid = $_POST['eventid'];
    $update = mysqli_query($con,"UPDATE calendar SET title='$title', startdate = '$startdate', enddate = '$enddate' where id='$eventid'");
    if($update)
        echo json_encode(array('status'=>'success'));
    else
        echo json_encode(array('status'=>'failed'));
}

if($type == 'remove')
{
    $eventid = $_POST['eventid'];
    $delete = mysqli_query($con,"DELETE FROM calendar where id='$eventid'");
    if($delete)
        echo json_encode(array('status'=>'success'));
    else
        echo json_encode(array('status'=>'failed'));
}

if($type == 'fetch')
{
    $events = array();
    $query = mysqli_query($con, "SELECT * FROM calendar");
    while($fetch = mysqli_fetch_array($query,MYSQLI_ASSOC))
    {
    $e = array();
    $e['id'] = $fetch['id'];
    $e['title'] = $fetch['title'];
    $e['start'] = $fetch['startdate'];
    $e['end'] = $fetch['enddate'];

    $allday = ($fetch['allDay'] == "true") ? true : false;
    $e['allDay'] = $allday;

    array_push($events, $e);
    }
    echo json_encode($events);
}


?>

最佳答案

这是我对 Laravel 的逻辑。

routes.php





     Route::get('/', function() {
                return View::make('hello');
        });

        Route::get('calender', 'CalendarController@showEvent');
        Route::post('calendar/add', 'CalendarController@postAdd');


Controller : CalendarController.php



    class CalendarController extends BaseController {

        function showEvent() {
            return View::make('display_event');
        }

        function postAdd() {
            echo json_encode($_POST);
        }

    }


查看脚本:display_event.php 下载查看:Click Here

请将 html 与 http://192.241.236.31/themes/preview/smartadmin/1.4.1/ajaxversion/#ajax/calendar.html (Ajax 日历 View )

通过 ajax 查看负载: http://192.241.236.31/themes/preview/smartadmin/1.4.1/ajaxversion/ajax/calendar.html

希望这对你有用。

关于php - 在 View 文件中可以写什么url代码来调用Laravel Controller中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34627268/

相关文章:

laravel - 409 冲突错误仅在 wifi 上仅在注册期间

javascript - 拖动事件时 FullCalendar 和 qTip UI 问题

javascript - FullCalendar - 根据事件标准每天显示图标

PHP 在内存中创建多个 CSV 文件然后压缩

php - 我的 PHP 脚本仅从表中返回一行

php - Windows 上的 PHP interactive 没有输出

php - 在 Apache VirtualHost 中配置别名和目录

php - Laravel - 在一个方法中返回多个值

javascript - 有没有办法在具有错误 v-if 语句的 div 中显示 div

javascript - FullCalendar 匹配部分内容的输入文本过滤器