Home > Article > Backend Development > Detailed explanation of PHP code specifications in PHP development specification manual_PHP tutorial
It involves many aspects, such as PHP code specifications, PHP file naming specifications, website development process, website security and maintenance, etc.
As the beginning of PHP development specifications, I will talk about what I think of PHP code specifications from the perspective of a pure PHP developer, mainly from the three perspectives of PHP directory framework structure, PHP code writing specifications, and PHP file naming specifications. Elaboration, I hope it will be helpful to beginners of PHP.
Reasonably build the PHP directory framework structure
We know that before using PHP for website development, we need to build the directory structure of the website. The design of the website directory framework structure is reasonable and standardized, which is not only conducive to website development, but also good for SEO, website Promotion is beneficial.
Generally, the most basic PHP website structure involves images, CSS files, JS files, third-party components, management background, etc. Correspondingly, the basic PHP directory framework structure also involves these contents. There are also standards for naming these directories. For example
Picture directory: images or pic
CSS directory: css
JS directory: js
Third-party component directory: libs or include. The next-level directory can define the directory name according to the specific component name
Management directory: It is usually admin. For security reasons, you can choose another directory name or set password protection for the admin directory. How to password-protect access to directories?
Special reminder: For the framework directory structure of the website, it is necessary to plan it in advance. In order to be friendly to search engines and facilitate website promotion, it is recommended that the directory structure level should not be too deep, and a two- and three-level directory structure will be enough.
In addition, if you use templates, you can create a template directory, for example, name the directory tpl. If you use a third-party template engine, such as smarty, you can decide whether to set up another directory according to your needs. PHP basic tutorial: Smarty installation tutorial
For medium-sized websites, you can also divide the website directory frame structure according to website functions, such as channels.
PHP file naming convention
Good PHP file naming convention is also an element of PHP development specifications, which is helpful for memory and easy to manage. There are also certain rules for naming PHP website program files, such as
PHP website homepage file Naming convention: index.php or index.html
CSS file naming convention: The main CSS file is named style.css. In addition, you can also name it for specific modules or channels. For example, the CSS file for users can be defined as user_style.css or u_style.css
JS file naming convention: the main JS file is named main.js or major.js, and other JS files are named according to specific pages or specific objects, such as the homepage JS file. It can be named index.js, and the JS file that serves user login can be named user_login.js, etc.
Website configuration file naming convention: config.php or default_config.php, etc.
Special reminder for file naming: considering portability when naming PHP files, always use lowercase names, and name them with the website directory name. Similarly, there are two ways to name files. One can use pinyin to name specific files, and the other can use simple and clear English words to name files. Do not name files casually, which will cause confusion in future maintenance.
PHP code writing standards
Good PHP code standards will help PHP introductory learners benefit from the PHP code you write, and will also help you maintain your code in the future.
1. Add necessary code comments to the PHP code you write, and the code comments should be standardized. For more basic PHP code writing specifications, please refer to the PHP basic syntax tutorial
2. Maintain good PHP code writing specifications , use indentation reasonably to keep the code beautiful.
3. When using the assignment character, the variable name, assignment character, and value are separated by spaces, that is,