PHP程序员helloworld,基于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
//指向網站根目錄
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
class IndexController extends Yaf_Controller_Abstract{
public function indexAction(){
$this->getView()->assign("content", "Hello world");
}
}
編輯視圖文件 templates/index/index.phtml
Hello World經過以上操作,在瀏覽器輸入網站127.0.0.1/yaf_test 就能看到Hello world的輸出了, 如果不能,請再檢查以上步驟是否做對!
總結
以上是生活随笔為你收集整理的PHP程序员helloworld,基于yaf的Hello world示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php拉查询封装,php实现搜索类封装示
- 下一篇: php命名空间 动态 new,PHP命名