PHP framework Yaf learning notes ---- Default behavior Yaf is a PHP framework written in C language. it is in the form of php Extensions. is it laruence )? The work laruence is a member of the PHP development team. PECL developer. Yaf, Taint, and other Pecl extension authors. Yaf-related articles www. laruence. comtagya PHP framework Yaf learning notes-default behavior
Yaf is a PHP framework written in C language, in the form of php Extensions. is it laruence )? Works
Laruence is a member of the PHP development team, who is an extension author of PECL, such as Pecl developer. Yaf and Taint.
Yaf related articles http://www.laruence.com/tag/yaf ?? Online Manual
The online manual system describes everything about Yaf. here, we will use it as a learning guide to list the default behaviors (contracts) of Yaf)
0. Yaf configuration file (php. ini style)
In fact, there are two parts. one is the beginning of the configuration "yaf." in php. ini, which usually does not need to be adjusted.
The other part is the configuration starting with "application." during Yaf_Application initialization.
?
Configuration can introduce php constant definition
1. Yaf must be configured. it is actually a directory setting.
yaf.directory=APP_PATHapplication.directory=APP_PATH
That is, the appliction script directory. at least one directory must be defined, and application. directory takes precedence.
2. Yaf has a complete set of directory organization and file naming rules.
All Yaf applications should follow the directory structure below
-Index. php // entry file -. htaccess // rewrite rule + conf |-application. ini // configuration file application/+ controllers-Index. php // Default controller + views | + index // controller-index. phtml // Default View + modules // Other modules-library-models // model Directory-plugins // plug-in Directory
?
Yaf supports both case sensitivity and no sensitivity, but I have not found the case sensitivity usage (in linux)
Class naming and search rules
Class name ???????????? Corresponding directory
ClassModel ????? Models
ClassPlugin ????? Plugins
ClassController controllers
Others ??????????????? Library
3. Yaf uses the class name containing the separator "_" in combination with the directory organization to complete the class loading management with the complete class naming rules.
For example, if you used a Bar file Bar. php in Yaf and loaded it automatically, you need to organize it like this.
Put Bar. php in a sub-directory under the library Directory, such as myclass
In addition, you need to change the class name (generally Bar) in Bar. php to MyClass_Bar.
That is to say, the class name must contain the specific explanation of the directory name
4. handle errors
Yaf can handle errors through a controller, which is declared in APP_PATH/controllers/Error. php.
class ErrorController extends Yaf_Controller_Abstract {...}
Of course, whether the error controller is effective is affected by the configuration.
application.dispatcher.throwException=1application.dispatcher.catchException=1
For more information, see the official examples.
5. view
The render view must specify the View template file. you can use the relative (application/views) path or absolute path.
6. routing
Yaf supports multiple levels of paths and regular routing. you can use configuration files to write routes, or use php scripts to write routes in Bootstrap. php.
In my opinion, the most attractive part of Yaf is:
PHP Framework in PHP extension, Yaf is the best form if there is no bucket effect caused by database access bottlenecks
After Yaf is used, the memory usage should be much lower in some applications.
?
7. BUG? I found the following problems and I don't know if it is a bug.
When Yaf matches the section of the configuration file, it does not exactly match the name. for example
[product]...
New Yaf_Application ("conf/app. ini", 'P') // can still be matched
?
8. MVC
Yaf provides a default MVC behavior like most Frameworks. for M (setdefamodule module), I have not found a method for the change to take effect.
C and V correspond to each other. of course they can have different names. you can set them using the setView method of Yaf_Dispatcher.
?
9. Singleton mode class, in Yaf
Yaf_Application
Yaf_Loader
Yaf_Dispatcher
Yaf_Registry
Yaf_Session
The class instance is a singleton, and the others are not
Note that if forward is used in the Yaf_Controller_Abstract inheritance class action, a new instance object will be generated.
?
10. non-nested Dispatcher (version 2.x or earlier)
Yaf processes non-nested requests, which means that all controllers are not nested. if a Controller is not executed completely, a transfer occurs, an unknown result or even error may occur. the forward provided by Yaf is processed only after the current Controller completes execution. Therefore, if the request is processed completely in MVC mode, to achieve the effect of nested processing, you need to implement your own code. process Description
Mainloopstart dispatchLoopStartup preDispatch // In fact, a loop is under the control of the forward. the request cannot be changed. the request can be forward, but the postDispatch forward request will be postponed, loop to preDispatch dispatchLoopShutdown can dispatch a new request and start a new dispatchLoopStartupmainloopend
?
?