matiasnamendola/slimpower-slim-example

v0.0.1-alpha 2016-12-06 18:25 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:09:13 UTC


README

Latest version Total Downloads

Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads composer.lock available

是 Slim Framework 的一个扩展,允许您在路由时使用闭包或回调的地方动态实例化控制器。

控制器可以从 Slim 的 DI 容器中可选地加载,这样您就可以根据需要注入依赖项。

此外,此扩展还可以轻松实现 JSON API。

安装

创建文件夹 /var/www/slimpower 并下载此存储库

在终端中

mkdir /var/www/slimpower
cd /var/www/slimpower
composer require matiasnamendola/slimpower-slim-example

或者您可以将此作为您的 composer.json 使用

{
    "require": {
        "slim/slim": "2.*",
        "matiasnamendola/slimpower-slim-example": "dev-master"
    }
}

.htaccess

这里是一个用于简单 RESTful API 的 .htaccess 示例

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</IfModule>

或者

<ifModule mod_headers.c>
    Header always set Access-Control-Allow-Headers "Authorization"
</ifModule>

Apache 虚拟主机

在文件夹 '/etc/apache2/sites-available' 中创建名为 'slimpower.conf' 的配置文件,内容如下

<VirtualHost *:80>
    ServerAdmin     webmaster@localhost
    ServerName      dev.slimpower.com
    DocumentRoot    /var/www/slimpower
    ErrorLog        /var/log/apache2/slimpower-custom-error.log
    CustomLog       /var/log/apache2/slimpower-custom.log common
    #TransferLog    /var/log/apache2/slimpower-custom.log
    
    <Directory /var/www/slimpower/>
        Options -Indexes
        AllowOverride AuthConfig FileInfo
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/x-javascript
        AddOutputFilterByType DEFLATE image/gif
    </Directory>
    
    <files "*.conf">
        order allow,deny
        deny from all
    </files>
    
    <files "*.ini">
        order allow,deny
        deny from all
    </files>
    
    <files "*.json">
        order allow,deny
        deny from all
    </files>
    
    <DirectoryMatch "^/.*/(\.git|CVS)/">
        Order deny,allow
        Deny from all
    </DirectoryMatch>
</VirtualHost>

然后,在终端中复制以下内容

sudo a2ensite 000-slimpower
sudo /etc/init.d/apache2 restart

或者

sudo a2ensite 000-slimpower
sudo service apache2 restart

鸣谢

许可协议

MIT 许可协议(MIT)。有关更多信息,请参阅许可文件

项目

查看 slimpower-slim