Skip to content

laruence/yaf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d55a65e · Feb 25, 2025
Feb 25, 2025
Jun 26, 2024
Sep 19, 2022
Dec 10, 2021
Feb 25, 2025
Feb 24, 2025
Apr 12, 2020
Dec 8, 2013
Jun 26, 2024
Jul 1, 2021
Sep 5, 2012
Aug 17, 2012
Oct 8, 2012
Jun 26, 2024
Jan 8, 2014
Mar 15, 2020
Jan 9, 2014
Jun 26, 2024
Feb 25, 2025
Feb 25, 2025
Jan 18, 2013
Dec 13, 2011
Dec 10, 2021
Mar 9, 2021
Sep 19, 2022
Apr 11, 2020
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Feb 11, 2015
Mar 9, 2021
Jun 26, 2024
Apr 10, 2020
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Mar 9, 2021
Jun 26, 2024
Jun 26, 2024
Jun 26, 2024
Feb 25, 2025
Mar 9, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Jun 15, 2021
Jul 21, 2021
Apr 18, 2020
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Feb 11, 2015
Dec 10, 2021
Dec 10, 2021
Feb 11, 2015
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Apr 10, 2020
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
May 19, 2022
Mar 4, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Mar 9, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Mar 9, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Dec 10, 2021
Apr 10, 2020
Jun 26, 2024
Jun 26, 2024
Jun 26, 2024
Dec 10, 2021
Apr 13, 2020
Jun 26, 2024
Jun 26, 2024
Jun 26, 2024

Repository files navigation

Yaf - Yet Another Framework

Build status Build Status

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

Requirement

Install

Install Yaf

Yaf is a 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

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 // libraries
  + 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 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 Application

http://www.example.com

Alternative

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

./yaf_cg -d output_directory [-a application_name] [--namespace]

More

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