logikostech / core
LT 项目核心
1.0.1
2016-08-08 18:49 UTC
Requires
- php: >=5.4
- ext-phalcon: ^2.0
- logikostech/common: 1.*
- vlucas/phpdotenv: ^2.2
Requires (Dev)
- phpunit/phpunit: ^4.0
This package is auto-updated.
Last update: 2024-09-21 19:47:35 UTC
README
LT 项目的核心。
Logikos\Application\Bootstrap
基本用法
// public/index.php $basedir = realpath(__DIR__.'/..'); $appdir = $basedir.'/app'; /** * Composer */ $composer = $basedir . '/vendor/autoload.php'; if (file_exists($composer)) include_once $composer; $boot = new Bootstrap([ 'basedir' => $basedir, 'appdir' => $appdir, 'confdir' => $appdir.'/config' ]); /** * get loaded config from Bootstrap, which will auto merge $confdir."/".getenv('APP_ENV').".php" */ $config = Bootstrap::getConfig(); /** * Include services */ $di = require APP_PATH . '/config/services.php'; echo $boot->getContent();
Logikos\Application\Bootstrap\Modules
如果你向 Bootstrap() 传递模块配置信息,无论是模块定义还是默认模块,则 Bootstrap 会自动尝试初始化模块 Bootstrap::initModules()
当然,你也可以始终手动初始化模块
$appdir = realpath(__DIR__.'/../app'); $boot = new Bootstrap($options); $boot->initModules( [ 'frontend' => [ 'className' => 'Frontend\Module', 'path' => $appdir.'/modules/frontend/Module.php' ], 'backend' => [ 'className' => 'Backend\Module', 'path' => $appdir.'/modules/backend/Module.php' ] ], [ 'defaultModule' => 'frontend', 'modulesDir' => $appdir.'/modules' ] ); echo $boot->getContent();
请注意,通过指定 modulesDir,我们实际上真的不需要定义模块,因为类会自动在 modulesDir 中查找和注册所有模块。此外,默认的 modulesDir 是 APP_DIR.'/modules',默认的默认模块是 'frontend',因此如果默认值适用于你的应用程序,则 $boot->initModules() 会自动运行,无需任何选项。
模块路由
默认情况下,Modules 类会自动将你的模块与路由器注册。它使用 /controller/action/params 作为默认模块,使用 /modulename/controller/action/params 作为所有非默认模块。然而,你可以在你的 ModuleDefinition 类中覆盖此设置。
class Module implements ModuleDefinitionInterface { public static function defineRoutes(DiInterface $di) { /* @var $router \Phalcon\Mvc\Router */ $router = $di->get('router'); $default = $router->getDefaults()['module']; $router->add("/customroute/foo/:params", array( 'module' => 'somemodule, 'controller' => 'index', 'action' => 'foo', 'params' => 1 ))->setName('somemodule_foo'); }