Yaf的安装与Hello,world测试

来源:互联网 发布:小蛮腰苏三 网络 编辑:程序博客网 时间:2024/04/30 05:26

1. 安装

Yaf是国内牛人惠新宸写的PHP扩展,是Yet Another Frameword的简称,php官网的文档维护的不好,可参考开发者自己网站上的手册:http://www.laruence.com/manual/。

有三种安装方式:源码、PECL和安装操作系统提供的包。

我用阿里云的服务器,ubuntu12.04,使用apt-get intall安装报错:

The following packages have unmet dependencies:
php5-yaf : Depends: phpapi-20090626

因此从https://pecl.php.net/package/yaf上下载源码,再安装:
其中XXX为源码解压后的目录

cd XXX
sudo phpize
sudo ./configure
sudo make
sudo make install

PS:查看命令行输出,注意解决报错信息。

自己本地的机器是ubuntu14.04,可以直接暗中系统提供的包:

sudo add-apt-repository ppa:mikespook/php5-yaf
sudo apt-get update
sudo apt-get install php5-yaf

至于PECL的安装方法,参考

pecl install yaf

安装成功后别忘记重启APACHE,使新安装的PHP插件生效:

sudo /etc/init.d/apache2 restart

sudo service apache2 restart

2. 测试

安装成功后可以测试一下,参照http://www.laruence.com/manual/,建立目录结构如下:

  • public
    • index.php
    • css
    • js
    • img
  • conf
    • application.ini
  • applicaion
    • controllers
      • Index.php
    • library
    • models
    • modules
    • plugins
    • views
      • index
        • index.phtml

其中:
index.php

<?phpdefine("APP_PATH",realpath(dirname(__FILE__).'/../'));$app = new Yaf_Application(APP_PATH.'/conf/application.ini');$app->run();?>

application.ini

[product]application.directory=APP_PATH"/application/"

Index.php

<?phpclass IndexController extends Yaf_Controller_Abstract{        public function indexAction(){                $this->getView()->assign("content","Hello, world!");        }}?>

index.phtml

<html>        <head>                <title>Test Page</title>        </head>        <body>                <?php echo $content?>        </body></html>

测试结果:

结果

0 0