Yet Another Framework Examples
예제 #1 고전적인 애플리케이션 디렉토리 레이아웃
- index.php
- .htaccess
+ conf
|- application.ini //application config
- application/
- Bootstrap.php
+ controllers
- Index.php //default controller
+ views
|+ index
- index.phtml //view template for default action
+ modules
- library
- models
- plugins
예제 #2 Entry
최상위 디렉토리의 index.php는 애플리케이션의 유일한 방법이므로 모든 요청을 다시 작성해야 합니다. (Apache + php_mod에서 .htaccess를 사용할 수 있습니다)
<?php
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
$app->bootstrap() //call bootstrap methods defined in Bootstrap.php
->run();
?>
예제 #3 Rewrite rule
#for apache (.htaccess)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
#for nginx
server {
listen ****;
server_name domain.com;
root document_root;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php$1 last;
}
}
#for lighttpd
$HTTP["host"] =~ "(www.)?domain.com$" {
url.rewrite = (
"^/(.+)/?$" => "/index.php/$1",
)
}
예제 #4 Application config
[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
예제 #5 Default controller
<?php
class IndexController extends Yaf_Controller_Abstract {
/* default action */
public function indexAction() {
$this->_view->word = "hello world";
//or
// $this->getView()->word = "hello world";
}
}
?>
예제 #6 Default view template
<html>
<head>
<title>Hello World</title>
</head>
<body>
<?php echo $word;?>
</body>
</html>
예제 #7 Run the Application
위의 예는 다음과 유사한 결과를 출력합니다.
<html> <head> <title>Hello World</title> </head> <body> hello world </body> </html>
메모: yaf@github에서 찾을 수 있는 Yaf 코드 생성기를 사용하여 위의 예를 생성할 수도 있습니다.