基于yaf的Hello world示例

 
更多

基于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的输出了, 如果不能,请再检查以上步骤是否做对!

打赏

本文固定链接: https://www.cxy163.net/archives/3613 | 绝缘体

该日志由 绝缘体.. 于 2016年01月04日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 基于yaf的Hello world示例 | 绝缘体
关键字: , , , ,

基于yaf的Hello world示例:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter