Gene Framework Document, gene framework
Welcome to the Gene framework
Latest Version: V1.2.2 Open Source Address: https://github.com/sasou/php-gene Author: sasou documentation address: http://php-gene.com/doc
Overview
- Introduction
Gene is a flexible, powerful, simple, and efficient c extension framework. Through careful design and efficient technology implementation, combined with database, cache and other class libraries, bring a new development experience.
- Features
- Directory structure
For gene applications, you can follow a directory structure similar to the following. After you are familiar with it, you can customize the directory structure.
App
├ ── Cache
│ └ ── Views
├ ── Ext
│ ├ ── Com
│ ─ ── Cache
│ Sampled-Db
│ ├-Queue
├ ── Config
├ ── Controllers
│ └ ── Admin
─ ── Models
│ ├ ── Admin
Parameter-Views
├ ── Admin
└ ── Web
Getting started
- Portal File
The entry file is the entrance of all requests. Generally, all requests are redirected to this entry file by using the rewrite rules.
define('APP_ROOT', __dir__ . '/app/');$app = new \Gene\Application();$app ->load("router.ini.php") ->load("config.ini.php") ->run();
- Route configuration file
You can configure the http Request Method (get, post, put, patch, delete, trace, connect, options, and head) and configure the route processing function: callback Function and class method (in the format of className @ methodName ).
$router = new \Gene\Router();$router->clear()->get("/", "\Controllers\Index@run")->error(404,function(){echo " 404 ";})->hook("before", function(){echo " before ";})->hook("after", function($params){echo " after ";});
- Variable configuration file
The configuration cache supports data types such as bool, int, long, string, array, and constant.
$config = new \Gene\Config(); $config->clear(); $config->set("_db",array( 'adapter' => 'Pdo\Mysql', 'host' => '127.0.0.1', 'port' => 3306, 'user' => 'root', 'password' => '123456', 'database' => 'demo', 'charset' => 'utf8', 'persistent' => false, )); $config->set("_cache",array('adapter' => 'Memcaches', 'servers' => array('default' => array('host' => '127.0.0.1','port' => 8888,'persistent' => true))));
- Controller File
For the \ Controllers \ Index @ run of the route configuration, the Controller directory is the Index. php file under the Controllers directory under the app directory, and the Action name is run.
namespace Controllers;class Index extends \Gene\Controller{ /** * run * @param type $params */ public function run() { echo 'run'; }}
- Run
Enter the Project address in the browser, for example, http: // localhost/
See the before run after output !!!
NOTE: If before run after is not displayed, check the PHP error log to find out where the problem is.