Fatal error: Call to a member function val() on a non-object on line 1018
Fatal error: Call to a member function val() on a non-object on line 1018
I have two tables, and I retrieve the string of table 2 using a left join of two tables on table1.specialID = table2.ID
I intend to show a list of strings from table 2 as a select box in the Editor form.
Table 1 has 3 columns: 1st is auto-increment unsigned ID, 2nd is non-unique unsigned specialID, 3rd is varchar/email.
Table 2 has 2 columns: 1st is unsigned ID. 2nd is string
I did basic initialization of Editor/Datatables and can show Editor forms and DataTables nicely.
However, I am unable to Create/Edit Datatable entries; but I can Remove entries.
Codes as below:
PHP
<?php
// DataTables PHP library
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;
$data = Editor::inst($db, 'AssignedGroupEmail', 'ID')
->field(
Field::inst('AssignedGroupEmail.GroupID')->validator('Validate::notEmpty'),
Field::inst('AssignedGroup.Name')->set(false),
Field::inst('AssignedGroupEmail.Email')->validator('Validate::email')
)
->leftJoin('AssignedGroup', 'AssignedGroupEmail.GroupID', '=', 'AssignedGroup.ID')
->process($_POST)
->data();
if ( !isset($_POST['action']) ) {
$data['AssignedGroup'] = $db
->selectDistinct('AssignedGroup', 'ID as value, Name as label')
->fetchAll();
}
echo json_encode($data);
JS
var editor; // use a global for the submit and return data rendering in the examples
(function($){
$(document).ready(function() {
editor = new $.fn.dataTable.Editor({
ajax: "php/assignEmailsEditor.php",
table: "#assignEmails",
fields: [{
label: "Assigned Group: ",
name: "AssignedGroupEmail.GroupID",
type: "select"
},{
label: "Email: ",
name: "AssignedGroupEmail.Email",
type: "text"
}
]
} );
$('#assignEmails').dataTable( { // INCLUDE IDENTIFIER FOR THE FORM HERE.
dom: "Tfrtip",
ajax: "php/assignEmailsEditor.php", // PHP CODE FOR THE EDITOR
columns: [ // COLUMN DATA TO BE DISPLAYED
{ data: "AssignedGroup.Name" },
{ data: "AssignedGroupEmail.Email" }
],
tableTools: {
sRowSelect: "os",
aButtons: [
{ sExtends: "editor_create", editor: editor },
{ sExtends: "editor_edit", editor: editor },
{ sExtends: "editor_remove", editor: editor }
]
},
initComplete: function(settings, json) { // This map to show dropdown options when using 'Edit' function
editor.field('AssignedGroupEmail.GroupID').update(json.AssignedGroup);
}
} );
} );
}(jQuery));
I used Chrome's debugger tools, and found the server-side return this error:
Fatal error: Call to a member function val() on a non-object in C:\xampp\htdocs\myProgram\php\lib\Editor\Editor.php on line 1018
Prior to this, I searched (http://code.datatables.net/forums/discussion/21662/editor-and-left-join-doesn-t-works-for-me), (http://www.datatables.net/forums/discussion/20815/not-unique-table-alias) and (http://datatables.net/examples/basic_init/hidden_columns.html) but somehow the same Fatal Error is triggering on server-side.
I wrote my code in a similar fashion for all other pages but can update successfully.
Why is it only this newly-created PHP page is giving such errors?
This question has an accepted answers - jump to answer
Answers
Hi,
Which version of Editor (and more importantly the PHP libraries) are you using? There was a bug in 1.3.1 whereby if the join table has a substring that matched the parent table Editor would get a bit confused... The 1.3.2 update fixes that: https://editor.datatables.net/download .
Regards,
Allan
I received the code from a colleague so I am not sure initially what version of Editor I am using.
However, after downloading V1.3.2 Editor Trial only, I copied the contents of the PHP folder of the Editor folder into my existing copy of PHP/Editor folder, and the problem seemed to have disappeared entirely. Interesting... so I might have been using V1.3.1 all along
Good to hear :-)
Allan