基於yaf的Hello world

原文來自:http://blog.sina.com.cn/s/blog_a3f0d682010196nl.htmlphp

假設個人例子的站點目錄爲/var/www/yaf_test css

 我採用的目錄結構以下
 - 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:html

    //指向網站根目錄apache

define("APP_PATH",  dirname(__FILE__));瀏覽器

$app = new Yaf_Application(APP_PATH."/conf/application.ini");app

$app->run();網站


編輯public/.htaccess重寫規則(apache):this

RewriteEngine On插件

RewriteCond %{REQUEST_FILENAME} !-fcode

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的輸出了,若是不能,請再檢查以上步驟是否作對!

相關文章
相關標籤/搜索