upcloo / micro-framework
这是一个基于 ZF2 组件构建的简单微框架
0.0.14
2014-02-02 15:56 UTC
Requires
- zendframework/zend-eventmanager: 2.2.*
- zendframework/zend-http: 2.2.*
- zendframework/zend-mvc: 2.2.*
- zendframework/zend-servicemanager: 2.2.*
Requires (Dev)
- behat/behat: 2.4.*@stable
- phpunit/phpunit: 3.7.*
README
这是一个基于 ZF2 组件的简单微框架。
许可
本项目遵循 MIT 许可协议发布。
##入门
在 scenario
文件夹中,你可以找到不仅是一个示例,还是一个典型的起点... 你可以使用你喜欢的项目文件夹,但一个好的起点是
- src
- Your
- Namespace
- tests
- Your
- Namespace
- web
- configs
入口点(web/index.php)
<?php
$loader = include __DIR__ . '/vendor/autoload.php';
$loader->add("Your", __DIR__ . '/../src');
$config = new UpCloo\App\Config\ArrayProcessor();
$config->appendConfig(include __DIR__ . '/../configs/app.php');
$engine = new UpCloo\App\Engine();
$boot = new UpCloo\App\Boot($config);
$app = new UpCloo\App($engine, $boot);
$app->run();
以下是一个配置(configs/app.php)
<?php
return array(
"router" => array(
"routes" => array(
"home" => array(
"type" => "Literal",
"options" => array(
"route" => "/walter",
'defaults' => array(
'controller' => 'Your\\Controller\\Name',
'action' => 'hello'
)
),
'may_terminate' => true,
)
)
),
"services" => array(
"invokables" => array(
"Your\\Controller\\Name" => "Your\\Controller\\Name",
),
"factories" => array(
"example" => function(\Zend\ServiceManager\ServiceLocatorInterface $sl) {
return "hello";
}
),
)
);
从控制器开始(src/Your/Controller/Name.php)
<?php
namespace Your\Controller;
use UpCloo\Controller\ServiceManager;
class Name
{
use ServiceManager;
public function hello()
{
$hello = $this->services()->get("example");
return $hello . " " . "world";
}
}
启动你的网络服务
php -S localhost:8080 -t web/ web/index.php
访问你的页面 -> localhost:8080/walter