原文来自:http://blog.sina.com.cn/s/blog_a3f0d682010196nl.htmlphp
假设个人例子的站点目录为/var/www/yaf_test css
我采用的目录结构以下
- index.php //入口文件
+ public
|- .htaccess //重写规则
|+ css
|+ img
|+ js
+ conf
|- application.ini //配置文件
+ application
|+ controllers
|- Index.php //默认控制器
|+ views
|+ index //控制器
|- index.phtml //默认视图
|+ modules //其余模块
|+ library //本地类库
|+ models //model目录
|+ plugins //插件目录
编写入口文件index.php:html
//指向网站根目录apache
define("APP_PATH", dirname(__FILE__));浏览器
$app = new Yaf_Application(APP_PATH."/conf/application.ini");app
$app->run();网站
编辑public/.htaccess重写规则(apache):this
RewriteEngine On插件
RewriteCond %{REQUEST_FILENAME} !-fcode
RewriteRule .* index.php
编辑配置文件conf/application.ini:
[product]
application.directory=APP_PATH "/application/"
编辑默认控制器application/controllers/Index.php:
<?php
class IndexController extends Yaf_Controller_Abstract{
public function indexAction(){
$this->getView()->assign("content", "Hello world");
}
}
?>
编辑视图文件templates/index/index.phtml:
<html>
<head><title>Hello World</title></head>
<body>
<?php echo $content; ?>
</body>
</html>
通过以上操做,在浏览器输入网站127.0.0.1/yaf_test 就能看到Hello world的输出了,若是不能,请再检查以上步骤是否作对!