1. Go to this page and download the library: Download jaxon-php/jaxon-symfony 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/ */
// src/EventSubscriber/JaxonSubscriber.php
namespace App\EventSubscriber;
use App\Controller\DemoController;
use App\Controller\JaxonController;
use Jaxon\Symfony\App\Jaxon;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use function is_array;
class JaxonSubscriber implements EventSubscriberInterface
{
public function __construct(private Jaxon $jaxon)
{}
public function onKernelController(ControllerEvent $event)
{
$controller = $event->getController();
// when a controller class defines multiple action methods, the controller
// is returned as [$controllerInstance, 'methodName']
if (is_array($controller)) {
$controller = $controller[0];
}
// Select the controllers with Jaxon related content.
if ($controller instanceof JaxonController || $controller instanceof DemoController) {
$this->jaxon->setup();
}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
];
}
}
use Jaxon\Symfony\App\Jaxon;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class JaxonController extends AbstractController
{
#[Route('jaxon', name: 'jaxon.ajax', methods: ['POST'])]
public function __invoke(Jaxon $jaxon)
{
if(!$jaxon->canProcessRequest())
{
return; // Todo: return an error message
}
$jaxon->processRequest();
return $jaxon->httpResponse();
}
}
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use function Jaxon\rq;
class DemoController extends AbstractController
{
#[Route('/', name: 'demo.home')]
public function __invoke()
{
// Print the page
return $this->render('demo/index.html.twig', [
'pageTitle' => "Symfony Framework",
]);
}
}
// templates/demo/index.html.twig
<!-- In page header -->
{{ jxnCss() }}
</head>
<body>
<!-- Page content here -->
</body>
<!-- In page footer -->
{{ jxnJs() }}
{{ jxnScript() }}
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-symfony": "^5.0"
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.