lightsuner/stack-codeigniter

此软件包的最新版本(dev-develop)没有可用的许可证信息。

这是一个用于与 stackphp.com 一起使用 Codeigniter 的包装器。

dev-develop 2014-06-16 12:23 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:28:57 UTC


README

Latest Stable Version Total Downloads

StackPHP

## 简介 这是 Codeigniter 的一个包装器。它实现了 HttpKernelInterface,允许您通过 StackPHP 使用 Codeigniter 与其他框架。

这个实现有很多乱码。如果您能帮助清理它,我将非常高兴。

## 安装

在您的 composer.json 中添加 stack-codeigniter

{
    "require": {
        "lightsuner/stack-codeigniter": "dev-develop"
    }
}

现在运行以下命令让 composer 下载组件

$ php composer.phar update lightsuner/stack-codeigniter

Composer 将组件安装到您的项目的 vendor/lightsuner 目录。

## 使用

将 index.php 替换为以下内容

use StackCI\Application as CIApplication;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;

require_once __DIR__.'/vendor/autoload.php';

$session = new Session();
$session->start();

$request = Request::createFromGlobals();
$request->setSession($session);


$ciApp = (new CIApplication(__DIR__, 'development'))->init();

$app = (new Stack\Builder())
    ->resolve($ciApp);

$response = $app->handle($request);

$response->send();

$app->terminate($request, $response);

您也可以在 Codeigniter 初始化之前执行一些代码。使用 StackCI\Application::beforeKernelLoad()

$ciApp = (new \StackCI\Application(__DIR__, 'development'))
    ->beforeKernelLoad(function(){

        //... some code goes here

        define('PUBPATH', FCPATH."public");

        if( ! ini_get('date.timezone')) {
            date_default_timezone_set('GMT');
        }

        //... some other code
    })
    ->init();

与 WanWizard 的 datamapper 一起使用

为了让它正确工作,您应该在 third_party/datamapper/bootstrap.php 中添加 STACKCIEXTPATH

....
if ( ! function_exists('load_class'))
{
	function &load_class($class, $directory = 'libraries', $prefix = 'CI_')

	......

	foreach (array(STACKCIEXTPATH, BASEPATH, APPPATH) as $path)
    		{
    			if (file_exists($path.$directory.'/'.$class.'.php'))
    			{
    				$name = $prefix.$class;

    				if (class_exists($name) === FALSE)
    				{
    					require($path.$directory.'/'.$class.'.php');
    				}

    				break;
    			}
    		}

    .....

然后加载 datamapper 的引导程序

$ciApp = (new CIApplication(__DIR__, 'development'))
    ->beforeKernelLoad(function(){
        //load Datamapper's bootstrap
        require_once APPPATH.'third_party/datamapper/bootstrap.php';
    })
    ->init();

## 详细信息

有一个 BaseApplication 和两个文件夹 - ExtOrig

  1. BaseApplication 与默认 Codeigniters 的 index.php 做同样的事情 - 加载并运行内核。
  2. Orig 包含 Codeigniter 的原始文件,如 Router、Input、Output、Loader 等。
  3. Ext 包含扩展文件

#### 新功能:Libraries/Session - 新方法 migrate

    $this->session->migrate($destroy, $lifetime);

Core/Input - 新方法 getRequest

    $this->input->getRequest();

## 建议

  • 使用 LazyHttpKernel 通过 stackPHP 与其他框架结合使用 stack-codeigniter