carloshlfz / framework
PHP应用程序开发框架。
v0.1.10
2021-08-19 17:33 UTC
Requires
- php: >=5.6
- akrabat/ip-address-middleware: 0.6
- clickalicious/memcached.php: 1.0.1
- doctrine/dbal: 2.5.13
- dompdf/dompdf: 0.8.2
- guzzlehttp/guzzle: 6.3.3
- illuminate/database: 5.4.36
- illuminate/events: 5.4.36
- kylekatarnls/coffeescript: 1.3.4
- leafo/scssphp: 0.7.5
- matthiasmullie/minify: 1.3.60
- predis/predis: 1.1.1
- slim/slim: 3.9.1
- smarty/smarty: 3.1.33
- swiftmailer/swiftmailer: 5.4.12
Requires (Dev)
- apigen/apigen: ^4.1
- phpunit/phpunit: 5.7.26
README
这是一个个人使用的轻量级框架,我在GitHub上提供它。它简化了我的一些服务,当然也可以用其他方式实现,但这个版本可能会帮助那些也需要它的人。
版本信息
此框架与PHP 5.6、7.0、7.1和7.2版本兼容。
依赖项
- slim/slim: 3.9.1
- akrabat/ip-address-middleware: 0.6
- smarty/smarty: 3.1.33
- guzzlehttp/guzzle: 6.3.3
- illuminate/database: 5.4.36
- illuminate/events: 5.4.36
- swiftmailer/swiftmailer: 5.4.12
- leafo/scssphp: 0.7.5
- matthiasmullie/minify: 1.3.60
- kylekatarnls/coffeescript: 1.3.4
- dompdf/dompdf: 0.8.2
- clickalicious/memcached.php: 1.0.1
安装
要安装,只需在Composer中运行以下命令
composer require carloshlfz/framework
使用方法
基本上,您需要启动应用程序。为此,您可以使用以下代码
<?php
require_once 'vendor/autoload.php';
class App extends CHZApp\Application
{
/**
* @see CHZApp\Application::init()
*/
public function init()
{
}
}
$app = new App;
$app->run();
这会使您的应用程序正常运行,并允许自动调用控制器。
控制器应在Controller命名空间下。示例
<?php
namespace Controller;
class Home extends \CHZApp\Controller
{
public function index_GET($response, $args)
{
return $response->write('hello world');
}
}
默认情况下,路由通过以下方式定义
http://127.0.0.1/
http://127.0.0.1/home
http://127.0.0.1/home/index
将使用Controller\Home在index_GET路由中
要添加新的控制器,只需继承CHZApp\Controller并正确命名控制器,然后进行调用。
http://127.0.0.1/test/hello
将使用Controller\Test在hello_GET路由中
http://127.0.0.1/test/hello/new/user
将使用Controller\Test在hello_new_user_GET路由中
对于POST类型的路由,后缀将GET更改为POST。
您可以通过以下方式在控制器内部访问$_POST, $_GET 和 $_REQUEST变量
<?php
namespace Controller;
class Home extends \CHZApp\Controller
{
public function index_GET($response, $args)
{
$name = $this->get['name'];
return $response->write('hello world');
}
public function index_POST($response, $args)
{
$name = $this->post['name'];
return $response->write('hello world');
}
}
为了使路由正常工作,您的.htaccess文件也需要相应配置。我建议使用
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
<FilesMatch "\.(xml|xsd|db|tpl|json|lock|zip|md|sql|log|cache|index|dist|txt|test|scss|js|png|gif|jpg|jpeg|gitignore|yaml|bat)$">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
Options -Indexes
此.htaccess文件与框架配合得非常好。