Table of Contents
Entry file
Rewrite rules
Configuration file
Controller
View file
Home Backend Development PHP Tutorial Start the yaf journey_PHP tutorial

Start the yaf journey_PHP tutorial

Jul 20, 2016 am 11:14 AM
a index.php public yaf start Table of contents structure

Directory structure

+ public  <span //</span><span 网站根目录</span>
   - index.php <span //</span><span 入口文件</span>
   - .htaccess <span //</span><span 重写规则    </span>
+<span  conf
  </span>|- application.ini <span //</span><span 配置文件   </span>
application/
  +<span  controllers
     </span>- Index.php <span //</span><span 默认控制器</span>
  +<span  views    
     </span>|+ index   <span //</span><span 控制器</span>
        - index.phtml <span //</span><span 默认视图</span>
  + modules <span //</span><span 其他模块</span>
  - library    <span //</span><span 组件目录</span>
  - models  <span //</span><span model目录</span>
  - plugins <span //</span><span 插件目录</span>
Copy after login

Entry file

The entry file is the entry point for all requests. Generally, all requests are redirected to this entry file with the help of rewrite rules.

A classic entry file public/index.php

<?<span php
</span><span define</span>("APP_PATH",  <span realpath</span>(<span dirname</span>(<span __FILE__</span>) . '/../')); <span /*</span><span  指向public的上一级 </span><span */</span>
<span $app</span>  = <span new</span> Yaf_Application(APP_PATH . "/conf/application.ini"<span );
</span><span $app</span>->run();
Copy after login

Rewrite rules

Unless we use query string-based routing protocols (Yaf_Route_Simple, Yaf_Route_Supervar), we need to use the Rewrite rules provided by WebServer to direct all requests for this application to the entry file mentioned above.

Modify .htaccess file

Nginx Rewrite (nginx.conf)

<span server {
  listen </span><span 80</span><span ;
  server_name  yaf.demo.com;
  root   document_root;
  index  index.php index.html index.htm;

  </span><span if</span> (!-<span e $request_filename) {
    rewrite </span>^/(.*)  /index.php/$<span 1</span><span  last;
  }
}</span>
Copy after login

Configuration file

In Yaf, the configuration file supports inheritance and sectioning. It also supports PHP constants. You don’t have to worry about parsing performance problems caused by too large a configuration file, because Yaf will load the configuration file when it is first run. , keep the formatted content in memory. It will not be loaded again until the configuration file is modified.

A simple configuration fileapplication/conf/application.ini

<span [common]
application.directory </span>= APP_PATH  <span "</span><span /application</span><span "</span><span 
application.dispatcher.catchException </span>= <span 0</span><span 
application.dispatcher.throwException </span>= <span 0</span><span 
application.view.ext </span>= <span '</span><span phtml</span><span '</span><span 
[product : common]
;enable the error controller
application.dispatcher.catchException</span>=<span 1</span>
Copy after login

Controller

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

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

Default Controllerapplication/controllers/Index.php

<?<span php
</span><span class</span> IndexController <span extends</span><span  Yaf_Controller_Abstract {
   </span><span public</span> <span function</span> indexAction() {<span //</span><span 默认Action</span>
       <span $this</span>->getView()->assign("content", "Hello World"<span );
   }
}
</span>?>
Copy after login

View file

Yaf supports simple view engines, and supports users to customize their own view engines, such as Smarty.

For the default module, the path of the view file is in the directory with the action name in lowercase in the views directory under the application directory.

A view of a default Actionapplication/views/index/index.phtml

<html>
 <head>
   <title>Hello yaf</title>
 </head>
 <body>
  <?php <span echo</span> <span $content</span>;?>
 </body>
</html>
Copy after login

Then enter the servername set in nginx.conf in the browser,

Table 4.2. Yaf optional configuration items

名称值类型默认值说明
application.ext String php PHP脚本的扩展名
application.bootstrap String Bootstrapplication.php Bootstrap路径(绝对路径)
application.library String application.directory + "/library" 本地(自身)类库的绝对目录地址
application.baseUri String NULL 在路由中, 需要忽略的路径前缀, 一般不需要设置, Yaf会自动判断.
application.dispatcher.defaultModule String index 默认的模块
application.dispatcher.throwException Bool True 在出错的时候, 是否抛出异常
application.dispatcher.catchException Bool False 是否使用默认的异常捕获Controller, 如果开启, 在有未捕获的异常的时候, 控制权会交给ErrorController的errorAction方法, 可以通过$request->getException()获得此异常对象
application.dispatcher.defaultController String index 默认的控制器
application.dispatcher.defaultAction String index 默认的动作
application.view.ext String phtml 视图模板扩展名
application.modules String Index 声明存在的模块名, 请注意, 如果你要定义这个值, 一定要定义Index Module
application.system.* String * 通过这个属性, 可以修改yaf的runtime configure, 比如application.system.lowcase_path, 但是请注意只有PHP_INI_ALL的配置项才可以在这里被修改, 此选项从2.2.0开始引入

<em id="__mceDel"><em id="__mceDel"><span <br /><br /></span></em></em>
Copy after login

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440265.htmlTechArticle目录结构 + public - index.php - .htaccess + |- application.ini application/ + - Index.php + |+ index - index.phtml + modules - library - models - plugins 入口文件 入口文件...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to insert a table of contents in Google Docs How to insert a table of contents in Google Docs Apr 13, 2023 pm 08:16 PM

Whether it is an article, paper or tutorial, the main highlight of any document is the title and of course the table of contents. It describes the outline structure of the document so that users can get to where and what they expect to read from the document. It's also a best practice to add a table of contents to most documents to make them look more professional. Today, everything happens online and people use Google Docs to create most documents. Many users are still not sure how to insert or add a table of contents in google docs. Therefore, we come up with this article to explain how to create or insert a table of contents in Google Docs. How to Insert a Table of Contents in Google Docs Step 1: Click here to visit Google Docs Online. Step 2: If

Use java's File.isDirectory() function to determine whether the file exists and is a directory type Use java's File.isDirectory() function to determine whether the file exists and is a directory type Jul 24, 2023 pm 06:57 PM

Use Java's File.isDirectory() function to determine whether a file exists and is of directory type. In Java programming, you often encounter situations where you need to determine whether a file exists and is of directory type. Java provides the File class to operate files and directories. The isDirectory() function can help us determine whether a file is a directory type. The File.isDirectory() function is a method in the File class. Its function is to determine the current File

PHP function introduction—rename(): Rename a file or directory PHP function introduction—rename(): Rename a file or directory Jul 25, 2023 pm 12:10 PM

PHP function introduction—rename(): Renaming files or directories Introduction: In PHP, the rename() function is used to rename files or directories. It provides an easy way to change the name of a file or directory. Whether it is a single file or an entire directory, you can use this function to perform a rename operation. The renaming process can be easily accomplished by specifying the name of the source file or directory and the target name. Syntax: boolrename(string$source,str

What is the difference between the developer version and the public version of iOS? What is the difference between the developer version and the public version of iOS? Mar 01, 2024 pm 12:55 PM

Every year before Apple releases a new major version of iOS and macOS, users can download the beta version several months in advance and experience it first. Since the software is used by both the public and developers, Apple has launched developer and public versions, which are public beta versions of the developer beta version, for both. What is the difference between the developer version and the public version of iOS? Literally speaking, the developer version is a developer test version, and the public version is a public test version. The developer version and the public version target different audiences. The developer version is used by Apple for testing by developers. You need an Apple developer account to download and upgrade it.

Get the directory portion of a file path using the path/filepath.Dir function Get the directory portion of a file path using the path/filepath.Dir function Jul 27, 2023 am 09:06 AM

Use the path/filepath.Dir function to obtain the directory part of the file path. In our daily development process, file path processing is often involved. Sometimes, we need to get the directory part of the file path, that is, the path to the folder where the file is located. In the Go language, you can use the Dir function provided by the path/filepath package to implement this function. The signature of the Dir function is as follows: funcDir(pathstring)string The Dir function receives a word

The glob() function in PHP is used to find files or directories The glob() function in PHP is used to find files or directories Nov 18, 2023 pm 06:17 PM

The glob() function in PHP is used to find files or directories and is a powerful file operation function. It can return the path of a file or directory based on a specified pattern match. The syntax of the glob() function is as follows: glob(pattern, flags) where pattern represents the pattern string to be matched, which can be a wildcard expression, such as *.txt (matching files ending with .txt), or a specific file path. flags is an optional parameter used to control the function

How to automatically generate a directory. How to set the format of the automatically generated directory. How to automatically generate a directory. How to set the format of the automatically generated directory. Feb 22, 2024 pm 03:30 PM

Select the style of the catalog in Word, and it will be automatically generated after the operation is completed. Analysis 1. Go to Word on your computer and click to import. 2After entering, click on the file directory. 3 Then select the style of the directory. 4. After the operation is completed, you can see that the file directory is automatically generated. Supplement: The table of contents of the summary/notes article is automatically generated, including first-level headings, second-level headings and third-level headings, usually no more than third-level headings.

How to read the catalog when reading on WeChat How to view the catalog How to read the catalog when reading on WeChat How to view the catalog Mar 30, 2024 pm 05:56 PM

The mobile version of WeChat Reading App is a very good reading software. This software provides a lot of books. You can read them anytime, anywhere with just one click to search and read them online. All of them are officially authorized and different types of books are neatly arranged. Sort and enjoy a comfortable and relaxing reading atmosphere. Switch the reading modes of different scenarios, update the latest book chapters continuously every day, support online login from multiple devices, and batch download to the bookshelf. You can read it with or without the Internet, so that everyone can discover more knowledge from it. Now the editor details it online Promote the method of viewing the catalog for WeChat reading partners. 1. Open the book you want to view the catalog and click in the middle of the book. 2. Click the three lines icon in the lower left corner. 3. In the pop-up window, view the book catalog

See all articles