jaxon-php / jaxon-yii
Jaxon library integration for the Yii Framework
Requires
- jaxon-php/jaxon-core: ^4.0
- yiisoft/yii2: ~2.0.14
This package is auto-updated.
Last update: 2024-11-15 19:50:21 UTC
README
This package integrates the Jaxon library into the Yii framework. It requires the version 2.0.11 or newer.
Installation
Add the following lines in the composer.json
file, and run the composer update
command.
"require": { "jaxon-php/jaxon-yii": "^4.0" }
Or run the composer require jaxon-php/jaxon-yii
command.
This package provides a filter that must be attached to routes to pages where the Jaxon features are enabled.
This is an example of a Yii controller using the Jaxon library.
namespace app\controllers; use Yii; use yii\web\Controller; use Jaxon\Yii\Filter\JaxonConfigFilter; class DemoController extends Controller { public function behaviors() { return [ [ 'class' => JaxonConfigFilter::class, 'only' => ['index', 'jaxon'], ], ]; } /** * Process Jaxon ajax requests. This route must be the same that is set in the Jaxon config. */ public function actionJaxon() { $jaxon = jaxon()->app(); if(!$jaxon->canProcessRequest()) { // Jaxon failed to find a plugin to process the request return; // Todo: return an error message } $jaxon->processRequest(); return $jaxon->httpResponse(); } /** * Insert Jaxon js and css codes in the page. */ public function actionIndex() { // Set the layout $this->layout = 'demo'; // Get the Jaxon module $jaxon = jaxon()->app(); return $this->render('index', [ 'jaxonCss' => $jaxon->css(), 'jaxonJs' => $jaxon->js(), 'jaxonScript' => $jaxon->script() ]); } }
Before it prints the page, the controller calls the $jaxon->css()
, $jaxon->js()
and $jaxon->script()
functions,
to get the CSS and javascript codes generated by Jaxon which are inserted into the page.
Configuration
The Jaxon library settings are defined in the @app/config/jaxon.php
file, and separated into two sections.
The options in the lib
section are those of the Jaxon core library, while the options in the app
sections are those of the Jaxon application.
The following options can be defined in the app
section of the config file.
By default, the views
array is empty. Views are rendered from the framework default location.
There's a single entry in the directories
array with the following values.
Usage
The Jaxon classes
The Jaxon classes can inherit from \Jaxon\App\CallableClass
.
By default, they are located in the @app/jaxon/ajax
dir of the Yii application, and the associated namespace is \Jaxon\Ajax
.
This is an example of a Jaxon class, defined in the @app/jaxon/ajax/HelloWorld.php
file.
namespace Jaxon\Ajax; class HelloWorld extends \Jaxon\App\CallableClass { public function sayHello() { $this->response->assign('div2', 'innerHTML', 'Hello World!'); return $this->response; } }
Contribute
- Issue Tracker: github.com/jaxon-php/jaxon-yii/issues
- Source Code: github.com/jaxon-php/jaxon-yii
License
The package is licensed under the BSD license.