Yaf framework entry-only helloyaf-PHP source code

Source: Internet
Author: User
0

Help you quickly get started with the Yaf framework

1. [Code][PHP] code
1. the organization directory structure is easy to understand for those who have used the framework. for those who have not used the framework, we recommend that you do not stop here. remember first, simply put, make some provisions on our file structure so that you and others can see clearly and quickly find the desired file or class. The author said that Yaf applications should follow a directory structure similar to the following. next we will look at a typical Yaf directory structure + public |-index. php // entry 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 library | + models // model Directory | + plugins // plug-in directory 2. the entry file framework must have one A unified entry file, the entry file is the entrance of all requests. generally, all requests are redirected to this entry file by using the rewrite rules. let's simply copy the code here, and then explain it one by one. next we will look at a typical entry file public/index. php
 Run (); 3. rewrite the URL because we need to set all requests from the website to the specified entry file, and then schedule the entry file to the module according to the requested url, controller, action processing, so we need to configure the server url rewriting. The following lists common Rewrite rules for Apache, Nginx, Lighttpd, and SAE. we can configure Apache Rewrite (httpd. conf )#. htaccess, of course, can also be written in httpd. confRewriteEngine OnRewriteCond % {REQUEST_FILENAME }! -FRewriteRule. * index. php // Nginx Rewrite (nginx. conf) server {listen *****; server_name domain.com; root document_root; index. php index.html index.htm; location/{index public/index. php; if (! -F $ request_filename) {rewrite ^/(. *)/public/index. php? $1 last ;}}// Lighttpd Rewrite (lighttpd. conf) $ HTTP ["host"] = ~ "(Www .)? Domain.com $ "{url. rewrite = (" ^/(. + )/? $ "=>"/Index. php/$1 ",)} // SAE Rewrite (config. yaml) name: your_app_nameversion: 1 handle:-rewrite: if (! Is_dir ()&&! Is_file () & path ~ "^ (. *) $") Goto "/index. php" Remember: after modifying the configuration file, remember to restart webserver! 4. the configuration file is in Yaf. The Framework encapsulates a configuration class for us. we just got into touch with it here, so we don't know about it, just remember and imitate it. 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 file application/conf/application. ini [product]; supports writing the defined constant application in PHP directly. directory = APP_PATH "/application/" 5. the default module/controller/action of the controller in Yaf is named after Index. 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 controller application/controllers/Index. php
 GetView ()-> assign ("content", "Hello Yaf") ;}}?> 6. 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 with lower-case action name in the views directory under the application directory. a default Action View application/views/index. phtml   Hello Yaf  
 

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.