DataTables Editor issue: PHP Fatal error: Uncaught Error: Class 'DataTables\\Editor' not found

DataTables Editor issue: PHP Fatal error: Uncaught Error: Class 'DataTables\\Editor' not found

TonyRTonyR Posts: 27Questions: 6Answers: 0

apache2 error log reports this error. The Chrome browser ->Javascript Console reports 500 (Internal Server Error).

Notes:
- The Editor examples downloaded from this site work perfectly on localhost.
- DataTables works perfectly alone (without Editor).
- The data is coming from MySQL, and the data in the config.php, in the same directory as DataTables.php, has been checked and rechecked.
- The page, controls, buttons all appear, just no data, and the message from localhost saying: "DataTables warning: table id=mainlist - Ajax error. For more information about this error, please see http://datatables.net/tn/7"
- mainlist is my html table.

Any clues would be GREATLY appreciated.

var editor;
    $(document).ready(function() {

        editor = new $.fn.dataTable.Editor( {
            ajax:  "Editor/php/maker_join.php",
            table: "#lookup_maker",
            fields: [
                { label: 'Name',      name: 'n'},
                { label: 'Address 1', name: 'a1' },
                { label: 'Address 2', name: 'a2' },
                { label: 'City',      name: 'c'},
                { label: 'State',     name: 's'},
                { label: 'Zip',       name: 'z' },
                { label: 'Phone',     name: 'p'}
            ]
        });

        $('#mainlist').DataTable( {             //     <-- this is where the yellow highlight ends up
            ajax: {
                url: "Editor/php/maker_join.php",
                type: 'POST'
            },
            dom: "Bfrtip",
            columns: [
                { data: 'n'},  
                { data: 'a1'},
                { data: 'a2'},
                { data: 'c'}, 
                { data: 's'},
                { data: 'z' },
                { data: 'p'}
            ],
            select: true,
            buttons: [
                { extend: 'create', editor: editor },
                { extend: 'edit',   editor: editor },
                { extend: 'remove', editor: editor }
            ]
        });
    });

And here is the data definition file:

<?php
 
// DataTables PHP library
include("Editor/php/DataTables.php");

use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\MJoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;
 
Editor::inst( $db, 'lookup_maker' , 'id' )
    ->fields(
        Field::inst( 'maker_name', 'n' )
        ->validator( Validate::notEmpty( ValidateOptions::inst()
            ->message( 'A name is required' ) 
            ) ),
        Field::inst( 'addr1', 'a1'),
        Field::inst( 'addr2', 'a2' ),
        Field::inst( 'city', 'c'),
        Field::inst( 'state', 's'),
        Field::inst( 'zip', 'z'),
        Field::inst( 'phone','p' )
    )
    ->process($_POST)
    ->json();

This question has an accepted answers - jump to answer

Answers

  • TonyRTonyR Posts: 27Questions: 6Answers: 0

    I forgot to revert back to the version without the obfuscation names, but these don't make any functional difference; the behavior was the same before I put those in.

  • TonyRTonyR Posts: 27Questions: 6Answers: 0

    The full error from the apache2 error log is: PHP Fatal error: Uncaught Error: Class 'DataTables\Editor' not found in /Users/tony/Sites/guns/Editor/php/maker_join.php:16

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Does the file /Users/tony/Sites/guns/Editor/php/Editor/Editor.php exist on your server? (Quite a lot of Editor's in that path!).

    The php directory from the PHP download should contain the DataTables.php file, Bootstrap.php a few others and the directories Database and Editor.

    Allan

  • TonyRTonyR Posts: 27Questions: 6Answers: 0

    Yes, ./Editor/php/Editor/Editor.php exist under my site root, and both the Database and Editor folders exist under ./Editor/php (along with files like Field.php, Format.php, Options.php, etc.). Also, Editor/php/bootstrap.php and Editor/php/config.php are also there.

    Thank you for your response, Allan.

  • TonyRTonyR Posts: 27Questions: 6Answers: 0

    AH!! Just discovered stupid mistake #1: My server script file, being in the same directory as DataTables.php, was using a path as if it were in the site root. I changed the include() statement to read:

    include("DataTables.php");
    

    ...and now I have table full of data. The Edit functionality is still an issue, but at least this is a step in the right direction.

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Hi Tony,

    Great to hear you've made progress with that. I'll reply to your e-mail about the editing shortly (I'm just spinning through the forum first :)).

    Regards,
    Allan

This discussion has been closed.