Compile Yaf from source on Linux
masterIf you need to install Yaf manually on Linux, use phpize and configure to build the extension.
$/path/to/phpize
$./configure --with-php-config=/path/to/php-config
$make && make installrepository·master·Indexed 26 days ago
https://github.com/laruence/yafA high-performance PHP framework written in C and distributed as a PHP extension. Yaf follows a classic MVC-like structure and includes the yaf_cg code generator for scaffolding application directory structures.
If you need to install Yaf manually on Linux, use phpize and configure to build the extension.
$/path/to/phpize
$./configure --with-php-config=/path/to/php-config
$make && make installA standard Yaf application follows this directory layout. Note that the public directory should be your DocumentRoot to ensure only the entry point is accessible to users.
- .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 // Pluginsyaf_cg tool is a PHP-based code generator used to scaffold the directory structure and initial files for a Yaf project. You can specify a directory name using the -d flag. Optionally, use the -n flag to generate a namespace example within the scaffolded project.Yaf is a PECL extension. You can install it using the following command:
$pecl install yafYou can configure the application using an application.ini file or by passing a PHP array to the Yaf_Application constructor.
#### Using application.ini
```ini
[product]
;CONSTANTS is supported
application.directory = APPLICATION_PATH "/application/" <?php
$config = array(
"application" => array(
"directory" => application_path . "/application/",
),
);
$app = new yaf_application($config);Yaf provides Yaf_View_Simple, which allows you to use PHP templates. Variables assigned to the view in the controller (e.g., $this->getView()->content) are available in the template.
<html
<head>
<title>Hello World</title>
</head>
<body
<?php echo $content; ?>
</body>
</html>The index.php file located in your public directory serves as the application entry point. It initializes the Yaf_Application using the configuration file and runs the bootstrap process.
<?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();The yaf_cg command accepts the following flags:
-d <directory_name>: Specifies the name of the directory to be generated (e.g., Sample). This directory will contain application/, conf/, index.php, and readme.txt.-n: Generates a namespace example within the scaffolded project.# Example output structure after running 'php yaf_cg -d Sample'
$ ls ./Sample/
application/ conf/ index.php readme.txtSince index.php is the only entry point, you must rewrite all requests to it using your web server's rewrite engine.
#### Apache (.htaccess)
```conf
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.phpserver {
listen ****;
server_name domain.com;
root document_root;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
}$HTTP["host"] =~ "(www.)?domain.com$" {
url.rewrite = (
"^/(.+)/?$" => "/index.php/$1",
)
}You can use the yaf_cg tool to scaffold a new application structure.
./yaf_cg -d output_directory [-a application_name] [--namespace]In Yaf, the default controller is named IndexController. Actions are defined as methods with the suffix Action (e.g., indexAction).
<?php
class IndexController extends Yaf_Controller_Abstract {
// default action name
public function indexAction() {
$this->getView()->content = "Hello World";
}
}
?>