Quick StartExample #1 A classic Application directory layout
- .htaccess // Rewrite rules
+ public/
| - index.php // Application entry
| + css/
| + js/
| + img/
+ conf/
| - application.ini // Application config
- application/
- Bootstrap.php // Bootstrap
+ controllers/
- Index.php // Default controller
+ views/
|+ index/
- index.phtml // View template for default action
+ library/ // Libraries
+ models/ // Models
+ plugins/ // Plugins
Set the web server Example #2 A multi-module Application directory layout
+ public/
+ conf/
+ application/
+ modules/
+ Index/ //default module
+ controllers/
+ views/
+ Admin/ //another module
+ controllers/
+ views/
+ library/
+ models/
+ plugins/
- Bootstrap.php
In a multi-module application, each module has its own
Example #3 Entry index.php in the public directory is the only way into the application, you should rewrite all requests to it (you can use .htaccess in Apache + mod_php, or the equivalent in your web server, see below). Example #4 Rewrite rule
#for apache (.htaccess)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
#for nginx
server {
listen 80;
server_name domain.com;
root document_root;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
}
#for lighttpd
$HTTP["host"] =~ "(www.)?domain.com$" {
url.rewrite = (
"^/(.+)/?$" => "/index.php/$1",
)
}
Example #5 Bootstrap
Any method of the Bootstrap class whose name
begins with Example #6 Application config application.ini is the application configuration file. Constants defined in index.php can be used in it, and sections can inherit from one another. [yaf] ;APPLICATION_PATH is the constant defined in index.php application.directory=APPLICATION_PATH "/application/" ;product section inherit from yaf section [product:yaf] foo=bar Example #7 Application config as a PHP array Besides an INI configuration file, a plain PHP array can also be passed to Yaf_Application::__construct as the configuration. Example #8 Default controller In Yaf, the default controller is named IndexController: Example #9 Default view template The view script for the default controller/action is application/views/index/index.phtml. Yaf provides a small view engine called Yaf_View_Simple, whose templates are plain PHP scripts. Example #10 Run the Application
Point the browser at the configured domain
(e.g. The above example will output something similar to: <html> <head> <title>Hello World</title> </head> <body> hello world </body> </html>
|