YAF Framework Installation Guide

Source: Internet
Author: User
Tags php error php error log php framework
This article mainly introduces about the YAF Framework installation Guide, has a certain reference value, now share to everyone, the need for friends can refer to

Speaking of the PHP framework, many people's impressions are stuck in a code package that is implemented by PHP in a variety of MVC-based feature combinations. Very few people know that C language can also write PHP framework, and faster than PHP written framework faster than 10 times times.

YAF is a PHP framework written in C language. It runs the framework in a way that PHP expands. Only the functions of the most central part of MVC are implemented: routing, MVC. the YAF core is compact enough to be stable, so there is almost no running problem. The risk is controllable and the performance is excellent. Of course, because it is simple, you need to implement the operation of enclosing the DB, extending the session, and so on.

As a PHP programmer, for the first programmer in Asia: Brother Bird, the framework should not be unfamiliar, then what are the advantages of it?

    • The C language-developed PHP framework provides little additional performance overhead compared to native PHP.

    • All framework classes do not need to be compiled, loaded at PHP startup, and resident memory.

    • Shorter memory turnaround cycles, improved memory utilization, and reduced memory usage.

    • Dexterous Auto-loading. It supports both global and local load rules, and facilitates the sharing of class libraries.

    • High-performance view engine.

    • A highly flexible and extensible framework that supports custom view engines, supports plug-ins, supports custom routing, and more.

    • Built-in multiple routes that are compatible with the various routing protocols that are common today.

    • Powerful and highly flexible configuration file support. The cache configuration file is supported to avoid the performance loss caused by complex configuration structure.

    • In the framework itself, the dangerous operating habits are prohibited.

    • Faster execution speed and less memory footprint.

Framework Installation:

One: Frame installation

yaf Extension Home:http://pecl.php.net/package/yaf

$ wget http://pecl.php.net/get/yaf-3.0.7.tgz$ tar-zxvf yaf-3.0.7.tgz$ cd yaf-3.0.7$/path/to/phpize$./configure-- with-php-config=/path/to/php-config$ make && make test && make install

Tip

The following error may occur when executing the command/path/to/phpize the compile command:

Configuring For:php API Version:         20151012Zend Module API No:      20151012Zend Extension API No:   320151012Cannot Find autoconf. Please check your autoconf installation and THE$PHP_AUTOCONF environment variable. Then, rerun the this script.

Refer to: https://blog.csdn.net/alen_xiaoxin/article/details/80255766, find a solution.

After compiling the build extension, modify the php.ini and add the following configuration at the end of the php.ini file:

[yaf]yaf.use_namespace = 0yaf.environ = ' product ' yaf.cache_config = 0yaf.name_suffix = 1yaf.lowcase_path = 1extension = Ya F.so

When you are finished adding, you can see if the phpinfo has a yaf extension.

Configuration Description:

    • A yaf.user_namespace of 1 is the open namespace mode. 0 off.

    • Yaf.environ is what the environment configuration is YAF read by default.

    • Yaf.cache_config whether the project configuration is cached.

    • Yaf.name_suffix to open the suffix. After 1, the class name is loaded in xxxmodel.php, xxxcontroller.php mode.

    • The portion of the directory in the Yaf.lowcase_path path information is converted to lowercase.

Ii. creation of the first YAF project

There are two ways to create them:


    1. Create a directory manually

    2. To generate a directory using the command line provided by YAF

The second method can be self to: https://github.com/laruence/php-yaf, download the source code, because YAF provides command tools with YAF source code together, under the project there is a tools folder, Inside is the command-line tool.

A typical directory structure:

+ Public
|-index.php//import file
|-htaccess/Rewrite rules
|+ CSS
|+ img
|+ JS
+ conf
|-Application.ini//configuration file
+ Application
|+ Controllers
|-index.php//Default Controller
|+ views
|+ index //Controller
|-index.phtml//default view
|+ modules//other modules
|+ Library//local class libraries
|+ Models //model Directory
|+ plugins//Plugin Directory

Entry file:

The portal file is the entry for all requests, and it is generally the rewrite rule that redirects all requests to the portal file.

A classic entry file for piublic/index.php:

<?phpdefine ("App_path",  Realpath (dirname (__file__). '/.. /')); /* point to the upper level of public *  /$app = new Yaf_application (App_path. "/conf/application.ini"); $app->run ();

Rewrite rule:

Apache's rewrite (httpd.conf):

#.htaccess, of course, can also be written in Httpd.confrewriteengine Onrewritecond%{request_filename}!-frewriterule. * index.php

Nginx's Rewrite (nginx.conf):

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;  }}

Configuration file:

In Yaf, the configuration file supports inheritance and supports sub-sections. and support for the constants of PHP. You don't have to worry about the configuration file too large to cause parsing performance problems, because YAF will load the configuration file at the first run and keep the formatted content in memory. The configuration file will not be loaded again until it has been modified.

A simple configuration file Application/application.ini:

[Product]; support for directly writing defined constants in PHP application.directory=app_path "/application/"

Controller:

In Yaf, the default module/Controller/action is named by index, which is, of course, modified by the configuration file.

For the default module, the controller directory is under the Controllers directory in the application directory, and the Action naming convention is "name +action"

Default Controller application/controllers/index.php

<?phpclass Indexcontroller extends Yaf_controller_abstract {public   function indexaction () {//default action       $ This->getview ()->assign ("Content", "Hello World");}   ? >

View File:

YAF supports a simple view engine and enables users to customize their own view engine, such as Smarty.

For the default module, the path to the view file is in the directory with the lower case action name in the Views directory under the application directory.

A view of the default action application/views/index/index.phtml


Run:

Enter the domain name of your server configuration in the browser:

http://www.yourhostname.com/application/index.php

I am locally configured directly to the port to the public directory, so direct input: localhost:8081, you can see

Attention:

If you don't see Hello World, go to the server and check the PHP error log to find out where the problem is.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.