Newbie having trouble with first steps
Newbie having trouble with first steps
While I'm a competent PHP programmer from the 5.x versions, but I'm clearly missing something here. I've followed the examples, setup (https://editor.datatables.net/manual/php/getting-started) by connecting to my database, and am running the following PHP:
// Running PHP Version 5.5.9-1ubuntu4.22
include("vendor/datatables/editor/php/DataTables.php");
use DataTables\Editor;
$editor = Editor::inst($db, 'system_logs', 'id');
Editor::inst( $db, 'system_logs', 'id' )
->fields(
Field::inst( 'user_uuid' )
);
When I run this, PHP errors with Fatal error: Class 'Field' not found in .../data_browser.php on line 7
I would have assumed that Field would be defined just like Editor, but I'm used to the OO model of $var = editor->function;
, so I may be missing something obvious.
-- Dave
Answers
Update, I am getting it to work (I think) with this syntax:
But I still can't explain why the example causes an error. Does 'Field' need to be prefixed as 'Editor\Field'?
At the link you posted, find this:
Now the complete example is:
which shows the use of PHP namespaces.
Yes, Editor's PHP libraries use namespaces to ensure code separation. You can either specify a fully qualified name space as you have above (
Editor\Field
,Editor\Join
, etc) or your can make use of PHP'suse
statement to allow it to be shorten like in the Editor example.If you have a look at the Editor PHP file examples you'll find:
at the top of all of them just to make the code a little easier to read (full namespaces everywhere doesn't make for attractive code).
SitePoint have a good tutorial on namespaces.
Allan