yaf安装及应用

环境安装

  • 下载地址:http://pecl.php.net/package/yaf
  • IDE自动补全V2.2.9版:https://github.com/xudianyang/yaf.auto.complete
  • 官方手册:http://yaf.laruence.com/manual
  • PHP文档:http://php.net/manual/zh/book.yaf.php
  • 安装:
解压进入目录
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

文档结构:

+ public
  |- index.php //入口文件
  |- .htaccess //重写规则 
  |+ css
  |+ img
  |+ js
+ conf
  |- application.ini //配置文件 
+ application
  |+ controllers
     |- index.php //默认控制器
  |+ views    
     |+ index   //控制器
        |- index.phtml //默认视图
  |+ modules //其他模块
  |+ library //本地类库
  |+ models  //model目录
  |+ plugins //插件目录

对应各文档内容:

public/index.php

<?php
define("_APP_PATH", realpath(dirname(__FILE__) . '/../')); /* 指向public的上一级 */
$app = new Yaf_Application(_APP_PATH . "/conf/application.ini");
$app->run();

public/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

conf/application.ini

[product]
;支持直接写PHP中的已定义常量
application.directory=_APP_PATH "/application/"

application/controllers/index.php

<?php class IndexController extends \Yaf_Controller_Abstract { public function indexAction() { $this->getView()->assign("content", "Hello Yaf."); } }

application/views/index.phtml

<html>
<head>
    <title>Hello Yaf</title>
</head>
<body>
<?php echo $content;?>
</body>
</html>

Nginx里的Conf:

server
    {
        listen 80;
        #listen [::]:80;
        server_name 域名;
        index index.html index.htm index.php;
        root  /home/wwwroot/【public的绝对地址】;

        include other.conf;
        #error_page 404 /404.html;
        include enable-php.conf;

        location / {
            if (!-e $request_filename) {
                rewrite ^/(.*) /index.php/$1 last;
            }
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\. { deny all; } access_log off; }

基本结构完成,然后可以访问了。

如果正常显示【Hello Yaf.】则表示配置完成。

你可能感兴趣的:(Yaf)