coryj
coryj

Reputation: 1255

Implementing non framework code into a framework such as laravel or codeigniter

I'm trying to implement AJAX Booking Calendar Pro into my Laravel application. (It was purchased from CodeCanyon) I've implemented most of the plugin, I just need to figure out how to connect it to the database so I can save and display the information. I'm using the controller approach. The start of the js file looks like this..

(function($)
{
    $.fn.DOPBookingCalendar = function(options)
    {
        var Data = {'Type':'BackEnd',
                'DataURL':'/php/load.php',
                'SaveURL':'/php/save.php',
                'DayNames':['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
                'MonthNames':['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
                'AvailableText':'AVAILABLE', // The available text.
                'BookedText':'BOOKED', // The Booked text.
                'UnavailableText':'NOT AVAILABLE', // The unavailable text.
                'DateType':1, // 1: american style; 2: european style;
                'PopupDisplayTime':300, // The time for the Pop-Up to Show/Hide
                'StatusLabel':'Status', // The text for Availability label.
                'PriceLabel':'Price', // The text for Price label.
                'Currency':'$', // The currency.
                'SubmitBtnText':'Submit', // The text for Submit button.
                'ResetBtnText':'Reset', // The text for Reset button.
                'ExitBtnText':'Exit', // The text for Exit button.
                'InvalidPriceText':'Error! Please enter a number for the price.' // The text for Invalid Price Warning.
               },

It seems to me that I it could be something as simple as setting the DataURL and SaveURL to a controller/model ... but how would I connect the database, and how do I know what fields the table would have? Hopefully someone will have experience with this.

//This is the save query

if (isset($_POST['dop_booking_calendar'])){
    require_once 'opendb.php';
    mysql_query('UPDATE schedule SET data="'.$_POST['dop_booking_calendar'].'" WHERE id=1');
}

//this is the load query

require_once 'opendb.php';

$query = mysql_query('SELECT * FROM schedule WHERE id=1');

while ($result=mysql_fetch_array($query)){
    echo $result['data'];
}

Upvotes: 0

Views: 534

Answers (2)

John C. Derrick
John C. Derrick

Reputation: 77

This may be obvious to some, but it took me a while since I'm new to working directly with mySQL and PHP. But I discovered I had to create a database called "schedule" along with two rows called "id" and "data" which allows the calendar to write data to them.

But I'm also getting stumped on the load.php file. I have successfully gotten the calendar to write data to the database using save.php, but the load.php file isn't retrieving the data. Very weird. I've tried the method Stefan provided, but still without any luck.

Anyone know how to retrieve the data from the database noted above? Here's my full load.php file.

<?php
    require_once 'opendb.php';

    $query = mysql_query('SELECT * FROM schedule WHERE id=1');

    while ($result=mysql_fetch_array($query)){
        echo $result['data'];
    }

?>

Upvotes: 0

Stefan Neubig
Stefan Neubig

Reputation: 1018

I think you should rewrite the Database Connection and Communication Part of the script and replace it with Laravels query builder.

E.g. change

mysql_query('SELECT * FROM schedule WHERE id=1');

Into:

$schedule = DB::query('SELECT * FROM schedule WHERE id=1');

Upvotes: 3

Related Questions