php程序员的笔记

  • 网站首页
  • PHP笔记
    • 字符串处理
    • php函数总结
    • 正则表达式
    • 模板框架使用
    • 我的网站模板笔记
    • Ecshop二次开发笔记
    • php源码下载
  • 数据库教程
    • MySQL数据库
    • MongoDB
    • Access数据库
    • Redis
  • JavaScript教程
    • Jquery基础
    • Jquery特效
    • JS常用函数
    • 开源插件开发
    • 谷歌地图开发
  • HTML教程
    • DIV+CSS技术篇
    • 网站优化笔记
    • HTML5 技术
  • 操作系统技巧
    • windows 7系统篇
    • Linux操作系统篇
    • 服务器
  • 互联网资讯
    • 生活杂侃
php程序员的笔记 -> PHP笔记 -> 模板框架使用 -> 基于yaf的Hello world示例

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

您可能感兴趣的文章

  • linux中编写第一个helloworld简单c语言程序
  • 该如何解决php运行出现Call to undefined function curl_init错误
  • 执行脚本出现binbash bad interpreter No such file or directory的决绝办法
  • 关于使用in_array() foreach array_search() 查找数组是否包含时的性能对比
  • PHP报Fatal error Allowed memory size of...内存不足的错误应该如何解决
  • 一个基于jQuery的弹出层 XYTipsWindow
  • 网页缓存控制 Cache-control 常见的取值有private、no-cache、max-age、must-revalidate 介绍
  • 快速查找并删除页面多余的CSS代码(Dust-Me Selectors的用法)
转载请注明出处:php程序员的笔记
本文永久地址:http://www.phpernote.com/php-template-framework/1196.html
发布时间:2016 年 01 月 06 日 16 时 21 分 36 秒     文章来源:-わ千与千寻
上一篇:php抽象类与接口的区别
下一篇:linux下查看和添加PATH环境变量
热门文章
  • php单一入口模式详细讲解
  • php+js 实现瀑布流效果
  • thinkphp 的 Action 控制器中的系统常量总结
  • ThinkPHP内置模板引擎的使用方法总结
  • JavaScript 如何处理 php 返回json格式的数据
  • smarty include file 使用变量的方法
随机文章
  • Yii获取上传文件的后缀名
  • thinkphp更新数据库的五种方法
  • Yii 动作方法技巧
  • Yii中validator之safe用法
  • yii rules验证示例总结
  • Yii控制器动作参数绑定处理
  • 周热门文章
    • smarty逻辑运算符号总结
    • PHP连接、操纵Memcached的原理和教程
    • thinkphp页面跳转(successerror)如何设置跳转等待时间
    • smarty循环操作
    • thinkphp 如何去除url中的index.php
    • smarty foreach详细说明
    • thinkphp打印最后一条sql语句
    • smarty模板执行原理
    • thinkphp关闭缓存的方法
    • yii数据库查询操作总结

All rights reserved. Design by -わ千与千寻.  京ICP备16025782号-1网站地图  友情连接有话要说私人建站招募投稿  广告服务  互联网工具大全