Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
PHP Framework in PHP extension
Failed to load latest commit information.
configs make code better
requests make code better
responses Fixed compile fails with VS
routes Fixed bug that segfault while abnormal map is given
tests Skip for 5.2 now (Segfault in travis but don't know why)
tools Fix shebang on yaf_cg
travis fix substitution
views make code better
.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 Change to https
config.m4 Fixed compile fails with VS
config.w32 Fixed compile fails with VS
package2.xml Update package2.xml
php_yaf.h fixed version macros name
yaf.c fixed version macros name
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 make code better
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 make code better
yaf_config.h Support dynmaic routing for Regex/Rewrite route
yaf_controller.c make code better
yaf_controller.h Support dynmaic routing for Regex/Rewrite route
yaf_dispatcher.c make code better
yaf_dispatcher.h
yaf_exception.c Remove unnecessary includes
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
yaf_plugin.c Remove unnecessary includes
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 make code better
yaf_request.h Support dynmaic routing for Regex/Rewrite route
yaf_response.c make code better
yaf_response.h Remove unnecessary includes
yaf_router.c make code better
yaf_router.h Support dynmaic routing for Regex/Rewrite route
yaf_session.c make code better
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

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 = APP_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.