kliksob/klikflight

KlikFlight 是一个航班微框架 MVC 应用程序架构。Flight 是一个快速、简单、可扩展的 PHP 框架。Flight 允许您快速轻松地构建 RESTful 网络应用程序。

dev-master 2018-02-10 05:33 UTC

This package is not auto-updated.

Last update: 2024-09-25 11:44:09 UTC


README

这是我第一个项目。

欢迎来到我的新仓库。

KlikFlight 是基于 Flight 微框架的 Web 应用程序框架,对于小型网站非常轻量,对于 RESTful 应用程序也非常好。

如何使用。

当您想要将此应用程序安装到项目中时,有两种选择。

第一种方式。

这是我最推荐的方式。使用 Composer 自动加载器。

在终端中输入。

$~ composer require kliksob/klikflight
$~ composer update

在您的公共根目录中创建 index.php 文件。

<?php
/**
 * This is Index.php File If you Use public directory
 */
define('APPROOT', __DIR__); // set root directory. not public
define('APPPATH', APPROOT. '/app'); // set your application directory
require_once APPROOT. '/vendor/autoload.php';
$app = new KlikFlight\App();
$app->start();

第二种方式。

下载此仓库

并更改 index.php 文件

请取消注释

// require_once APPPATH. '/src/vendor/autoload.php';

并在该行添加注释

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

这将无需 Composer 即可工作。适用于小型项目。

配置

/app/config.php

return [
	/* Basic Config */
	'config' => [
	],
	/* Framework Config */
	'framework'	=> [
		'default.index'		=> 'index',
		'case_sensitive' 	=> false,
		'views.path'		=> APPPATH. '/view/',
		'views.extension'	=> '.php',
		'model.prefix'		=> '_model',
		'helper.prefix'		=> '_helper',
		'library.prefix'	=> '_lib',
		'base_url'			=> '',
		'handle_errors'		=> true,
		'log_errors'		=> true
	]
];

路由

/app/route.php

/**
 * Object Method Routing
 */

$home = new HomeController();
Flight::routeGet('/', array($home, 'index'));
Flight::routeGet('/flight', array($home, 'getFlightInstance'));
Flight::routeGet('/test(/*)', array($home, 'test'));

/**
 * Static Method Routing
 */

class RouteStatic{
	static function example(){
		echo 'Hello Static';
	}
}
Flight::route('/static', array('RouteStatic', 'example'));

// For Specific Method
//Flight::routeAny($route, $callback);
//Flight::routeGet($route, $callback);
//Flight::routePost($route, $callback);
//Flight::routePut($route, $callback);
//Flight::routePatch($route, $callback);
//Flight::routeDelete($route, $callback);
//Flight::routeHead($route, $callback);
//Flight::routeTrace($route, $callback);
//Flight::routeOptions($route, $callback);

/**
 * Controller Method Routing pass All Public Class Object Method
 * Static Method Does't Work.
 */

Flight::routeController('/blog', 'TestController');

/**
 * Regular Method Routing
 */

Flight::route('/regular', function(){
	echo '<pre>';
	print_r(Flight::app());
	
});

是我添加的。以下功能不在 flight 框架中。有关路由引擎的更多信息,请参阅 http://flightphp.com/learn/#routing

使用 Flight::routeController();

<?php
class Example{
	public function __construct(){
		// the constructor
	}
	public function anyIndex(){
		echo 'i am receipe anything';
		//This Will get Anything method * http://example.com/controller/ or http://example.com/controller/index
	}
	public function getData($var1 = '', $var2 = null){
		echo 'i am receipe get';
		// This will only GET method like http://example.com/controller/data(/@var1)(/@var2)
	}
	public function postData(){
		echo 'i am receipe post';
		// This will only POST method like http://example.com/controller/data
	}
	public function putData(){
		echo 'i am receipe put';
		// This will only PUT method like http://example.com/controller/data
	}
	public function deleteData(){
		echo 'i am receipe delete';
		// This will only DELETE method like http://example.com/controller/data
	}
}
Flight::routeController('/controller', 'Example');
// You can Pass With Namespace
Flight::routeController('/controller', 'Mynamespace\Example');

请注意:静态类不工作。

加载模型

Flight::model('modelname', $args = array()); // Model Name Without Prefix

这将获取模型实例。

加载库

Flight::library('libraryname', $args = array()); // Library Name Without Prefix.

这将获取模型实例。

加载助手

Flight::helper('helpername', $args = array()); // Helper Name Without Prefix

这将包含您的助手。

有关 Flight 的更多文档信息 http://flightphp.com/learn/

您也可以为此仓库做出贡献。请。

谢谢。