PHP code example of jaxon-php / jaxon-yii

1. Go to this page and download the library: Download jaxon-php/jaxon-yii library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jaxon-php / jaxon-yii example snippets


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()
        ]);
    }
}

namespace Jaxon\Ajax;

class HelloWorld extends \Jaxon\App\CallableClass
{
    public function sayHello()
    {
        $this->response->assign('div2', 'innerHTML', 'Hello World!');
        return $this->response;
    }
}
json
""jaxon-php/jaxon-yii": "^4.0"
}