Start a yaf tour

Source: Internet
Author: User

Directory structure

+ public     - index.php    - .htaccess +|- application.ini application/  +- Index.php   +|+ index           - index.phtml   + modules   - library      - models    - plugins 
Portal File

The entry file is the entrance of all requests. Generally, all requests are redirected to this entry file by using the rewrite rules.

A classic portal file public/index. php

<?("APP_PATH",  (() . '/../'));   =  Yaf_Application(APP_PATH . "/conf/application.ini"->run();
Rewrite Rules

Unless we use the query string-based routing protocol (Yaf_Route_Simple, Yaf_Route_Supervar), we need to use the Rewrite rules provided by WebServer to request all the applications, all are directed to the above-mentioned entry file.

Modify the. htaccess File

Nginx Rewrite (nginx. conf)

 (!-^/(.*)  /index.php/$
Configuration File

In Yaf, configuration files support inheritance and can be segmented. and supports PHP constants. you don't have to worry about parsing performance problems caused by too many configuration files, because Yaf will load the configuration file at the first run and keep the formatted content in the memory. it will not be loaded again until the configuration file has been modified.

A simple configuration fileapplication/conf/application.ini

= APP_PATH  = = = =
Controller

In Yaf, the default modules, controllers, and actions are all named after indexes. Of course, this can be modified through the configuration file.

For the default module, the Controller directory is under the controllers directory under the application directory, and the Action naming rule is "name + Action"

Default Controllerapplication/controllers/Index.php

 
<? IndexController   indexAction() {       ->getView()->assign("content", "Hello World"?>
View File

Yaf supports simple view engines and allows you to customize your own view engines, such as Smarty.

For the default module, the path of the View File is in the directory named lower-case action in the views directory under the application directory.

View of a default Actionapplication/views/index/index.phtml

 

Enter the servername set in nginx. conf in the browser,

 

Table 4.2. Optional Yaf configuration items

Name Value Type Default Value Description
Application. ext String Php PHP script Extension
Application. bootstrap String Bootstrapplication. php Bootstrap path (absolute path)
Application. library String Application. directory + "/library" Absolute directory address of the local (itself) Class Library
Application. baseUri String NULL The prefix of the path to be ignored in the route. Generally, you do not need to set the prefix. Yaf automatically determines the prefix.
Application. dispatcher. defaultModule String Index Default Module
Application. dispatcher. throwException Bool True Whether to throw an exception when an error occurs
Application. dispatcher. catchException Bool False Whether to use the default exception capture Controller. If enabled, when an uncaptured exception exists, the control is handed over to the errorAction method of ErrorController. You can use $ request-> getException () to obtain the exception object.
Application. dispatcher. defaultController String Index Default Controller
Application. dispatcher. defaultAction String Index Default action
Application. view. ext String Phtml View template Extension
Application. modules String Index Declare the existing Module name. Note that if you want to define this value, you must define the Index Module.
Application. system .* String * This attribute can be used to modify the runtime configure of yaf, such as application. system. lowcase_path. However, note that only the PHP_INI_ALL configuration item can be modified here. This option is introduced from 2.2.0.

 


Related Article

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.