基于yaf的Hello world示例

PHP 投稿 15600 0 评论

基于yaf的Hello world示例

这篇关于基于yaf的Hello world示例的文章,觉得挺不错的,感兴趣的php开发者可以参考下,希望对大家在学习php的成长路上有所帮助!

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

总结

以上就是关于基于yaf的Hello world示例全部内容,希望这篇文章能够帮你解决如相关的PHP问题,更多请关注PHP栏目的其它相关文章!

编程笔记 » 基于yaf的Hello world示例

赞同 (83) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽