Blame view

Slim/README.markdown 6.31 KB
219b8036   luigser   DEEP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
  # Slim Framework
  
  [![Build Status](https://travis-ci.org/slimphp/Slim.svg?branch=master)](https://travis-ci.org/slimphp/Slim)
  
  Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
  Slim is easy to use for both beginners and professionals. Slim favors cleanliness over terseness and common cases
  over edge cases. Its interface is simple, intuitive, and extensively documented — both online and in the code itself.
  Thank you for choosing the Slim Framework for your next project. I think you're going to love it.
  
  ## Features
  
  * Powerful router
      * Standard and custom HTTP methods
      * Route parameters with wildcards and conditions
      * Route redirect, halt, and pass
      * Route middleware
  * Resource Locator and DI container
  * Template rendering with custom views
  * Flash messages
  * Encrypt cookie data
  * HTTP caching
  * Logging with custom log writers
  * Error handling and debugging
  * Middleware and hook architecture
  * Simple configuration
  
  ## Getting Started
  
  ### Install
  
  You may install the Slim Framework with Composer (recommended) or manually.
  
  [Read how to install Slim](http://docs.slimframework.com/#Installation)
  
  ### System Requirements
  
  You need **PHP >= 5.3.0**. If you use encrypted cookies, you'll also need the `mcrypt` extension.
  
  ### Hello World Tutorial
  
  Instantiate a Slim application:
  
      $app = new \Slim\Slim();
  
  Define a HTTP GET route:
  
      $app->get('/hello/:name', function ($name) {
          echo "Hello, $name";
      });
  
  Run the Slim application:
  
      $app->run();
  
  ### Setup your web server
  
  #### Apache
  
  Ensure the `.htaccess` and `index.php` files are in the same public-accessible directory. The `.htaccess` file
  should contain this code:
  
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [QSA,L]
  
  Additionally, make sure your virtual host is configured with the AllowOverride option so that the .htaccess rewrite rules can be used:
  
     AllowOverride All
  
  #### Nginx
  
  The nginx configuration file should contain this code (along with other settings you may need) in your `location` block:
  
      try_files $uri $uri/ /index.php?$args;
  
  This assumes that Slim's `index.php` is in the root folder of your project (www root).
  
  #### HipHop Virtual Machine for PHP
  
  Your HipHop Virtual Machine configuration file should contain this code (along with other settings you may need).
  Be sure you change the `ServerRoot` setting to point to your Slim app's document root directory.
  
      Server {
          SourceRoot = /path/to/public/directory
      }
  
      ServerVariables {
          SCRIPT_NAME = /index.php
      }
  
      VirtualHost {
          * {
              Pattern = .*
              RewriteRules {
                      * {
                              pattern = ^(.*)$
                              to = index.php/$1
                              qsa = true
                      }
              }
          }
      }
  
  #### lighttpd ####
  
  Your lighttpd configuration file should contain this code (along with other settings you may need). This code requires
  lighttpd >= 1.4.24.
  
      url.rewrite-if-not-file = ("(.*)" => "/index.php/$0")
  
  This assumes that Slim's `index.php` is in the root folder of your project (www root).
  
  #### IIS
  
  Ensure the `Web.config` and `index.php` files are in the same public-accessible directory. The `Web.config` file should contain this code:
  
      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="slim" patternSyntax="Wildcard">
                          <match url="*" />
                          <conditions>
                              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                          </conditions>
                          <action type="Rewrite" url="index.php" />
                      </rule>
                  </rules>
              </rewrite>
          </system.webServer>
      </configuration>
  
  #### Google App Engine
  
  Two steps are required to successfully run your Slim application on Google App Engine. First, ensure the `app.yaml` file includes a default handler to `index.php`:
  
      application: your-app-name
      version: 1
      runtime: php
      api_version: 1
      
      handlers:
      # ...
      - url: /.*
        script: public_html/index.php
  
  Next, edit your `index.php` file so Slim knows about the incoming URI:
  
      $app = new Slim();
      
      // Google App Engine doesn't set $_SERVER['PATH_INFO']
      $app->environment['PATH_INFO'] = $_SERVER['REQUEST_URI'];
      
      // ...
      $app->run();
  
     
  ## Documentation
  
  <http://docs.slimframework.com/>
  
  ## How to Contribute
  
  ### Pull Requests
  
  1. Fork the Slim Framework repository
  2. Create a new branch for each feature or improvement
  3. Send a pull request from each feature branch to the **develop** branch
  
  It is very important to separate new features or improvements into separate feature branches, and to send a pull
  request for each branch. This allows me to review and pull in new features or improvements individually.
  
  ### Style Guide
  
  All pull requests must adhere to the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) standard.
  
  ### Unit Testing
  
  All pull requests must be accompanied by passing unit tests and complete code coverage. The Slim Framework uses
  `phpunit` for testing.
  
  [Learn about PHPUnit](https://github.com/sebastianbergmann/phpunit/)
  
  ## Community
  
  ### Forum and Knowledgebase
  
  Visit Slim's official forum and knowledge base at <http://help.slimframework.com> where you can find announcements,
  chat with fellow Slim users, ask questions, help others, or show off your cool Slim Framework apps.
  
  ### Twitter
  
  Follow [@slimphp](http://www.twitter.com/slimphp) on Twitter to receive news and updates about the framework.
  
  ## Author
  
  The Slim Framework is created and maintained by [Josh Lockhart](http://www.joshlockhart.com). Josh is a senior
  web developer at [New Media Campaigns](http://www.newmediacampaigns.com/). Josh also created and maintains
  [PHP: The Right Way](http://www.phptherightway.com/), a popular movement in the PHP community to introduce new
  PHP programmers to best practices and good information.
  
  ## License
  
  The Slim Framework is released under the MIT public license.
  
  <http://www.slimframework.com/license>