Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
a php framework written in c, built in php-ext
C PHP C++
Failed to load latest commit information.
configs Fixed Issue #97
requests fix a bug
responses [-Wformat=]
routes fix issue #134
tests Added tests for #134
tools added some TODOs.. fixed typos and a possible bug fix
travis Fix typo
views Assign should return $this not boolean
.gitattributes attributes
.travis.yml Add PHP 5.5 into test cycles
CREDITS 1. Fixed issues #4
EXPERIMENTAL initial commit
LICENSE Add LICENSE file
README.md Fixed error due to undefined constant in example
check-package.sh Missing files, fix #82
config.m4 Fixed compile fails with VS
config.w32 try to fix windws build
package.xml prepare for 2.3.3
php_yaf.h back to dev
yaf.c Fixed version constant
yaf.dsp Add working folder to include path
yaf.php initial commit
yaf_action.c Remove unnecessary includes
yaf_action.h Support dynmaic routing for Regex/Rewrite route
yaf_application.c fix bug (issues #80)
yaf_application.h Support dynmaic routing for Regex/Rewrite route
yaf_bootstrap.c Remove unnecessary includes
yaf_bootstrap.h Support dynmaic routing for Regex/Rewrite route
yaf_config.c better macro condition
yaf_config.h Support dynmaic routing for Regex/Rewrite route
yaf_controller.c Fixes few minor typos in argument and method names
yaf_controller.h Support dynmaic routing for Regex/Rewrite route
yaf_dispatcher.c Fixed bug (Exception in preDispatch is not caught)
yaf_dispatcher.h Support dynmaic routing for Regex/Rewrite route
yaf_exception.c Fixed memory leak in 5.2
yaf_exception.h Support dynmaic routing for Regex/Rewrite route
yaf_loader.c make code better
yaf_loader.h Support dynmaic routing for Regex/Rewrite route
yaf_logo.h Support dynmaic routing for Regex/Rewrite route
yaf_namespace.h Support dynmaic routing for Regex/Rewrite route
yaf_plugin.c Fix signature
yaf_plugin.h Support dynmaic routing for Regex/Rewrite route
yaf_registry.c Remove unnecessary includes
yaf_registry.h Support dynmaic routing for Regex/Rewrite route
yaf_request.c Fixes few minor typos in argument and method names
yaf_request.h Support dynmaic routing for Regex/Rewrite route
yaf_response.c refactor the implementation
yaf_response.h move setAllHeaders、clearHeaders、getHeader、setHeader to yaf_response_h…
yaf_router.c Merge branch 'dev' of https://github.com/wenjun1055/php-yaf
yaf_router.h Fixed issue #69
yaf_session.c Add Yaf_Session::clear
yaf_session.h Support dynmaic routing for Regex/Rewrite route
yaf_view.c Fixed compile fails with VS
yaf_view.h Support dynmaic routing for Regex/Rewrite route

README.md

Yaf - Yet Another Framework

Build Status

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

Requirement

  • PHP 5.2 +

Install

Install Yaf

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

$pecl install yaf

Compile Yaf in Linux

$/path/to/phpize
$./configure --with-php-config=/path/to/php-config
$make && make install

For windows

Yaf binary dlls could be found at http://code.google.com/p/yafphp/downloads/list

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

$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/",
    ),
);

$app  = new yaf_application($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 engineer called "Yaf_View_Simple", which supported the view template written by 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

Something went wrong with that request. Please try again.