PHP Classes

File: HOWTO.md

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Jaxon   HOWTO.md   Download  
File: HOWTO.md
Role: Example script
Content type: text/markdown
Description: Example script
Class: Jaxon
Call PHP classes from JavaScript using AJAX
Author: By
Last change:
Date: 4 years ago
Size: 1,461 bytes
 

Contents

Class file image Download

Jaxon 3.x :: Quick start

Register a single class

jaxon()->register(Jaxon::CALLABLE_CLASS, 'HelloWorld');

Register all classes in a directory

jaxon()->register(Jaxon::CALLABLE_DIR, '/full/path/to/dir');

Register all classes in a namespace

jaxon()->register(Jaxon::CALLABLE_DIR, '/full/path/to/dir', [
    'namespace' => '\Path\To\Namespace',
]);

Register a function

jaxon()->register(Jaxon::CALLABLE_FUNCTION, 'sayHello');

Register a method as a function

// The corresponding javascript function name is 'setColor'
jaxon()->register(Jaxon::CALLABLE_FUNCTION, 'setColor', [
    'class' => 'HelloWorld',
]);

Register a method as a function with an alias

// The corresponding javascript function name is 'helloWorld'
jaxon()->register(Jaxon::CALLABLE_FUNCTION, 'sayHello', [
    'class' => 'HelloWorld',
    'alias' => 'helloWorld',
]);

Call a registered class

<button onclick="<?php echo rq('HelloWorld')->call('sayHello') ?>" >Click Me</button>

Call a registered class with a parameter

<button onclick="<?php echo rq('HelloWorld')->call('sayHello', 0) ?>" >Click Me</button>
<button onclick="<?php echo rq('HelloWorld')->call('setColor', pr()->select('color')) ?>" >Click Me</button>

Call a registered function

<button onclick="<?php echo rq()->call('sayHello') ?>" >Click Me</button>