linux 安装yaf框架

0 篇文章 0 订阅
下载yaf源码
wget http://pecl.php.net/get/yaf-3.0.8.tgz
或者从github下载 https://github.com/laruence/yaf(github中有tools目录,可用来生成脚手架)
tar -zxvf yaf*
cd yaf*
$PHP_BIN/phpize  使用phpize生成configure文件
再安装yaf扩展库
./configure --with-php-config==$PHP_BIN/php-config(PHP_BIN是PHP的bin目录)
make && make install

安装扩展库完成

配置php

在php.ini中载入yaf.so, 重启PHP.

运行代码生成工具:

cd tools/cg
./yaf_cg demo
会在yaf_cg文件相同的目录下创建一个output文件夹:

/Users/helloxiaozhu/php-yaf/tools/cg/output
进入之后就会看见你刚才创建的文件夹:demo
然后在这个目录中的output目录中就可以看到新生成的test脚手架代码了,拷贝到你的项目目录继续开发即可。

yaf官方安装文档

Yaf - Yet Another Framework

PHP framework written in c and built as a PHP extension.

Requirement

PHP 5.2 +

Install

Install Yaf

Yaf is a PECL extension, thus you can simply install it by:

$pecl install yaf

Compile Yaf in Linux

wget http://pecl.php.net/get/yaf-3.0.8.tgz
$/path/to/phpize
$./configure --with-php-config=/path/to/php-config
$make && make install

Document

Yaf manual could be found at: http://www.php.net/manual/en/book.yaf.php

IRC

efnet.org #php.yaf

For IDE

You could find a documented prototype script here: https://github.com/elad-yosifon/php-yaf-doc

Tutorial

layout

A classic application directory layout:

  • .htaccess // Rewrite rules
  • public
    | - index.php // Application entry
    | + css
    | + js
    | + img
  • conf
    | - application.ini // Configure
  • application/
    • Bootstrap.php // Bootstrap
    • controllers
      • Index.php // Default controller
    • views
      |+ index
      - index.phtml // View template for default controller
    • library
    • models // Models
    • plugins // Plugins
DocumentRoot

You should set DocumentRoot to application/public, thus only the public folder can be accessed by user

index.php

index.php in the public directory is the only way in of the application, you should rewrite all request to it(you can use .htaccess in Apache+php mod)

<?php
define("APPLICATION_PATH",  dirname(dirname(__FILE__)));

$app  = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
$app->bootstrap() //call bootstrap methods defined in Bootstrap.php
    ->run();
Rewrite rules
Apache

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

Nginx

server {
listen ****;
server_name domain.com;
root document_root;
index index.php index.html index.htm;

if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
}

Lighttpd

H T T P [ &quot; h o s t &quot; ] =   &quot; ( w w w . ) ? d o m a i n . c o m HTTP[&quot;host&quot;] =~ &quot;(www.)?domain.com HTTP["host"]= "(www.)?domain.com" {
url.rewrite = (
“^/(.+)/?$” => “/index.php/$1”,
)
}

application.ini

application.ini is the application config file

[product]
;CONSTANTS is supported
application.directory = APPLICATION_PATH "/application/" 

Alternatively, you can use a PHP array instead:

	<?php
	$config = array(
	   "application" => array(
	       "directory" => application_path . "/application/",
	    ),
	);

a p p = n e w y a f a p p l i c a t i o n ( app = new yaf_application( app=newyafapplication(config);

default controller

In Yaf, the default controller is named IndexController:

<?php
class IndexController extends Yaf_Controller_Abstract {
   // default action name
   public function indexAction() {  
        $this->getView()->content = "Hello World";
   }
}
?>

###view script The view script for default controller and default action is in the application/views/index/index.phtml, Yaf provides a simple view engine called “Yaf_View_Simple”, which support the view template written in PHP.

<html>
 <head>
   <title>Hello World</title>
 </head>
 <body>
   <?php echo $content; ?>
 </body>
</html>
Run the Applicatioin

http://www.yourhostname.com/

Alternative

You can generate the example above by using Yaf Code Generator: https://github.com/laruence/php-yaf/tree/master/tools/cg

More

More info could be found at Yaf Manual: http://www.php.net/manual/en/book.yaf.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值