PHP Classes

File: HOWTO.md

Recommend this page to a friend!
  Packages 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: Merge commit 'ad2bbee761f90bd5be9ed7cafe1099856dc7827b' as 'jaxon-core'
Date: 4 months ago
Size: 1,502 bytes
 

Contents

Class file image Download

Jaxon 3.x :: Quick start

Import the functions

use Jaxon\jaxon;
use Jaxon\rq;

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')->sayHello() ?>" >Click Me</button>

Call a registered class with a parameter

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

Call a registered function

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