Jan
04
2016
基于yaf的Hello world示例
作者:
绝缘体.. 发布:
2016-01-04 11:44 分类:
未分类 阅读:
抢沙发
基于yaf的Hello world示例,假设我的例子的站点目录为 /var/www/yaf_test ,我采用的目录结构如下:
– 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
<?php
//指向网站根目录
define("APP_PATH", dirname(__FILE__));
$app = new Yaf_Application(APP_PATH."/conf/application.ini");
$app->run();
编辑 public/.htaccess重写规则(apache)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
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的输出了, 如果不能,请再检查以上步骤是否做对!
微信扫一扫,打赏作者吧~