Home > PHP Framework > YII > body text

Where to place public methods in Yii

王林
Release: 2020-02-17 14:54:16
Original
2909 people have browsed it

Where to place public methods in Yii

This introduction is based on the yii2-advanced version:

Where to place public methods in Yii

The above picture shows the basic directory structure of the yii2-advanced version. The ./common directory is a public resource directory, and we can place the defined public methods in this directory.

In this directory, we can create a file at will, such as the "helps" directory. Considering that public methods may be divided into functional categories, we create a unified directory for management.

(Recommended tutorial: yii framework)

Where to place public methods in Yii

Two tool classes are established here.

YII2 adopts PHP’s new feature namespace

Establishing public methods

<?php
namespace common\helps;
/*
 * 自定义全局公共方法
 */
class tools{
  public static function hello(){
    echo &#39;hello world!&#39;;
  }
}
?>
Copy after login

For more programming-related content, you can follow php Chinese websiteProgramming Tutorial column!

The above is the detailed content of Where to place public methods in Yii. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
yii
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!