jaxon-php / jaxon-codeigniter
CodeIgniter 框架的 Jaxon 库集成
v4.0.2
2022-10-06 07:10 UTC
Requires
- codeigniter4/framework: 4.*
- jaxon-php/jaxon-core: ^4.0
This package is auto-updated.
Last update: 2024-08-30 15:59:25 UTC
README
本软件包将 Jaxon 库 集成到 CodeIgniter 4 框架中。
安装
本软件包的版本 4 需要 CodeIgniter 版本 4。
使用 Composer
安装本软件包。
composer require jaxon-php/jaxon-codeigniter ^4.0
或者
{ "require": { "jaxon-php/jaxon-codeigniter": "^4.0", } }
运行 composer install
。
过滤器
本软件包提供了一个过滤器,必须将其附加到启用 Jaxon 功能的所有页面的路由上。
在 app/Config/Routes.php
文件中,必须为 Jaxon 请求定义一个路由。
// Add the Jaxon filter to Jaxon-enabled routes. $routes->get('/', 'Demo::index', ['filter' => JaxonConfigFilter::class]); // Jaxon request processing route. $routes->post('/jaxon', 'Demo::jaxon', ['filter' => JaxonConfigFilter::class]);
以下是一个使用 Jaxon 库的 CodeIgniter 控制器的示例。
namespace App\Controllers; use Jaxon\Demo\Ajax\Bts; use Jaxon\Demo\Ajax\Pgw; use function view; class Demo extends BaseController { public function index() { $jaxon = jaxon()->app(); // Print the page return view('demo/index', [ 'jaxonCss' => $jaxon->css(), 'jaxonJs' => $jaxon->js(), 'jaxonScript' => $jaxon->script(), 'pageTitle' => "CodeIgniter Framework", // Jaxon request to the Bts Jaxon class 'bts' => $jaxon->request(Bts::class), // Jaxon request to the Pgw Jaxon class 'pgw' => $jaxon->request(Pgw::class), ]); } public function jaxon() { $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(); } }
配置
将本软件包中的 config/Jaxon.php
文件复制到 CodeIgniter 应用的 app/Config
目录。
config/Jaxon.php
配置文件中的设置分为两个部分。位于 lib
部分的选项是 Jaxon 核心库的选项,而位于 app
部分的选项是 CodeIgniter 应用的选项。
可以在配置文件的 app
部分定义以下选项。
默认情况下,views
数组为空。视图从框架默认位置渲染。在 directories
数组中有一个条目,具有以下值。
用法
Jaxon 类
Jaxon 类可以继承自 \Jaxon\App\CallableClass
。默认情况下,它们位于 CodeIgniter 应用的 jaxon/app
目录,关联的命名空间是 \Jaxon\Ajax
。
以下是一个简单的 Jaxon 类示例,定义在 jaxon/ajax/HelloWorld.php
文件中。
namespace Jaxon\Ajax; class HelloWorld extends \Jaxon\App\CallableClass { public function sayHello() { $this->response->assign('div2', 'innerHTML', 'Hello World!'); return $this->response; } }
贡献
- 问题跟踪器:github.com/jaxon-php/jaxon-codeigniter/issues
- 源代码:github.com/jaxon-php/jaxon-codeigniter
许可证
本软件包采用 BSD 许可证。