Error in Generator Code

Error in Generator Code

tgalfanotgalfano Posts: 7Questions: 4Answers: 0
edited August 2015 in General

I get the following error when I create a new record using the Gerenrator code on my local XAMPP server :

Warning: call_user_func() expects parameter 1 to be a valid callback, class '\DataTables\Editor\Validate' not found in C:\--Projects--\test\php\lib\Editor\Field.php on line

Answers

  • tgalfanotgalfano Posts: 7Questions: 4Answers: 0

    I downloaded the complete package and placed it in a directory.

    • Executed the SQL
    • Changed the Database Configration in the config file.
    • When I run the HTML file I can see a table with no records.
    • When I click on the "New" button, a modal opens up with the fields.
    • After entering the values in the form field, I click on the "Create" button.
    • After click the Create button I get the error A system error has occurred (More information).
    • When I do inspect element and see the server response I can see the following error :

    Warning: call_user_func() expects parameter 1 to be a valid callback, class '\DataTables\Editor\Validate' not found in C:\--Projects--\test\php\lib\Editor\Field.php on line

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi,

    Could you let me know what validation options you have selected, and/or paste the generated PHP into this conversation and I'll fix that. Thanks!

    Allan

  • tgalfanotgalfano Posts: 7Questions: 4Answers: 0
    <?php
    
    /*
     * Editor server script for DB table lokesh
     * Created by http://editor.datatables.net/generator
     */
    
    // DataTables PHP library and database connection
    include( "lib/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'lokesh', 'id' )
        ->fields(
            Field::inst( 'title' )
                ->validator( 'Validate::notEmpty' ),
            Field::inst( 'description' )
                ->validator( 'Validate::notEmpty' )
        )
        ->process( $_POST )
        ->json();
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Thanks for the code. I'm having problems reproducing this issue I'm afraid - I've just setup a similar generator table and it appears to run as expected.

    Could you check in the php/lib/Editor directory and make sure that there is a Validate.php file there please? Also, what version of PHP are you using?

    Allan

  • tgalfanotgalfano Posts: 7Questions: 4Answers: 0

    Yes there is a Validate.php file and the version of PHP I am using is PHP Version 5.3.1

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    I have a feeling that this is a namespace bug in early versions of PHP 5.3.x. There were some really wacky bug in the early 5.3 series. I suspect it isn't resolving the Validate library from the use statement like it should.

    If you were to use:

    ->validator( '\DataTables\Editor\Validate::notEmpty' ),
    

    does that resolve the issue (or possibly without the leading \)?

    The other option is to update to a newer version of 5.3.x (or even 5.x).

    Allan

This discussion has been closed.