Uncaught Error: Class 'Options' not found

Uncaught Error: Class 'Options' not found

Pliachas PaschalisPliachas Paschalis Posts: 68Questions: 13Answers: 1

this is my code:

<?php

/*
 * Editor server script for DB table pOrder
 * Created by http://editor.datatables.net/generator
 */

 $loggedid="";

 if ( isset($_POST['loggedid']) ) $loggedid=$_POST['loggedid'];

// 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;

// The following statement can be removed after the first run (i.e. the database
// table has been created). It is a good idea to do this to help improve
// performance.
$db->sql( "CREATE TABLE IF NOT EXISTS `pOrder` (
    `id` int(10) NOT NULL auto_increment,
    `fcar` numeric(9,2),
    `pdate` date,
    `pvalue` numeric(9,2),
    PRIMARY KEY( `id` )
);" );

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'pOrder' )
    ->field(
        // Field::inst( 'pOrder.fcar' )
        //  ->options( Options::inst()
        //      ->table( 'tblaCars' )
        //      ->value( 'id' )
        //      ->label( 'pCar' )
        //      ->where( function ($q) {
        //          $q->where( 'tblaCars.loggedid', $loggedid, '=' );
        //  })
        //  ->validator( 'Validate::dbValues' )
        // ),
        Field::inst( 'pOrder.fcar' )
            ->options( Options::inst()
                ->table( 'tblaCars' )
                ->value( 'id' )
                ->label( 'pCar' )
            )
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'tblaCars.pCar' ),
        Field::inst( 'tblaCars.pName' ),
        Field::inst( 'tblaCars.loggedid' ), 
        Field::inst( 'pOrder.pdate' )
            ->validator( 'Validate::dateFormat', array( 'format'=>'d/m/y' ) )
            ->getFormatter( 'Format::date_sql_to_format', 'd/m/y' )
            ->setFormatter( 'Format::date_format_to_sql', 'd/m/y' ),
        Field::inst( 'pOrder.pValue' )
    )
    
    ->leftjoin('tblaCars', 'tblaCars.id', '=', 'pOrder.fCar')
    ->where( "loggedid", $loggedid)
    ->process( $_POST )
    ->json();

and i get the following error:
Fatal error: Uncaught Error: Class 'Options' not found in /home/sites/4b/f/f905e34be3/public_html/php/table.pOrder.php:49 Stack trace: #0 {main} thrown in /home/sites/4b/f/f905e34be3/public_html/php/table.pOrder.php on line 49
when my code was (in Editor part):

Editor::inst( $db, 'pOrder', 'id' )
    ->fields(
        Field::inst( 'pOrder.fcar' )
            ->options('tblaCars','id','pCar')
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'tblaCars.pCar' ),         
        Field::inst( 'tblaCars.pName' ),
        Field::inst( 'pOrder.pdate' )
            ->validator( 'Validate::dateFormat', array( 'format'=>'d/m/y' ) )
            ->getFormatter( 'Format::date_sql_to_format', 'd/m/y' )
            ->setFormatter( 'Format::date_format_to_sql', 'd/m/y' ),
        Field::inst( 'pOrder.pValue' )
    )

it was working Ok.
I tried to change that to get only the records that meet a criteria, and i found that link https://editor.datatables.net/manual/php/joins#Options in your site
but since then the table doesn't load records.
Any help?
Thanks in advance

Answers

  • Pliachas PaschalisPliachas Paschalis Posts: 68Questions: 13Answers: 1

    Looking more carefully on the bottom of the site saw a comment from user brendons

    "@v1.6.111:47, Mon 19th Dec 2016

    (v1.6.0+) When updating an existing php page to use the new Options class don't forget to add the Options 'use' statement at the top of the file"
    

    So following his advise everything now works fine.
    Thanks

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    edited October 2017

    That's the one. Thanks for the update!

    Allan

This discussion has been closed.