Introduction to thinkphp5

1. The php framework helps facilitate rapid application development, not only saves time, helps build more stable applications, but also reduces the development of repetitive code.

It is generally considered that the role of a PHP framework is equivalent to a model, a controller, and a view. (mvc)


2. Advantages of thinkphp5.0

① Chinese development, more in line with our way of thinking, easy to get started

②Open source, free, fast and simple object-oriented lightweight development PHP framework

③Support Composer, PHPunit (a necessary dependency management and testing framework for medium and large projects)

④Extraordinarily rigorous error detection and security mechanism Detailed log information escorts our development

⑤Reduces core dependencies, makes expansion more flexible and convenient, and supports command line instruction expansion

⑥Mechanism to support automatic loading

⑦ Refactored database support and association


3. Installation (official website download, Composer installation, Git installation)

After downloading, put it in the wamp/www directory


4. Configure the virtual host and deploy the framework

①Open three configuration items in c\wamp64\bin\apache2.4.17\conf\httpd.conf. (Cancel the # in front of it)

LoadModule rewrite_module modules/mod_rewrite.so

LoadModule vhost_alias_module modules/mod_vhost_alias.so

Include conf/extra/httpd-vhosts.conf

②Add a virtual host in c\wamp\bin\apache\apache2.4.17\conf\extra\httpd-vhosts.conf.

rewrite

# Virtual Hosts
#


<VirtualHost *:80>
ServerName www.tp5.com
ServerAlias localhost
DocumentRoot c:\wamp\www\tp5\public
<Directory  "c:c:\wamp\www\tp5\public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

#

③C:\Windows\System32\drivers\etc\hosts 添加 127.0.0.1    www.tp5.com


4. URL access

In the framework, the template, controller, and operation name are not written in the url address. By default, the index operation under the index controller under the index module is accessed. You can modify C:\wamp\www\tp5\application\index in the config.php file. \controller\index.php

Modify the style at the return

Modify C:\wamp\www\tp5\application\config.php


Modified here

Entry file C:\wamp\www\tp5\public\index.php


5. Development Specifications

ⅠDirectories and files

①The directory is not mandatory, and both lowercase and underscore modes are supported.

②The class library and function files are unified with .php as the suffix

③The file names of the classes are defined by the namespace, and the path of the namespace is the same as the path where the class library file is located (the paths are inconsistent and cannot be loaded automatically)


④ The class name and the class file name should be consistent, and the name should be unified in camel case (the first letter is capitalized)

Ⅱ函数和类,属性命名

①类的命名采用驼峰法,并且首字母大写,User'Type默认不加后缀,如UserController应该直接命名为User

②函数命名使用小写或者下划线(小写字母开头)如,get_client_lip

③方法的命名使用驼峰法,并且首字母小写,如,tableName,instance

Ⅲ常量与配置

①常量以大写字母和下划线命名,如APP_PATH

②配置参数以小写字母和下划线命名,如,url_rotute_on

Ⅳ数据表和字段

①数据表和字段采用小写加下划线方式命名,注意字段名不能以下划线开头,如。think_user表和user_nanme字段,不建议使用驼峰法和中文作为数据表字段命名

Ⅴ应用类命名空间规范

①应用类的根命名空间统一为app(可以设置app_namesoace配置参数更改)

如app\index\controller\Index 和app\index\model\User config.php(里面找)

Ⅵ注意事项

避免使用PHP保留的字(http://php.net/manual/zh/reserved.keywords.php),否者会造成系统错误

时间:2018.4.14

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324384234&siteId=291194637