这篇文章给大家介绍TP5相关解决问题有哪些,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
TP5相关解决问题
1.默认入口文件public,其他文件不允许访问
2.在application内部,后台一般放在admin内,前台代码一般放在index内,遵循MVC架构
3.application文件夹中的文件作用
- command.php 命令行启动TP5框架需要读取的文件
- common.php 常用的函数,都写在这个文件中
- config.php 配置文件,开启什么,关闭什么,都在这设置
- database.php 连接数据库时候读取的文件,比如用户名
- route.php 路由文件,美化url的
- tags.php 扩展框架的时候用到
4.public内文件作用
- static 这里放的是css、html之类的静态文件
- favicon.ico 这个是网站图标,在标签栏显示的
- index.php 网站入口文件,所有的请求都会经过这里
- robots.txt 禁止搜索引擎爬取页面的设置
- router.php 在没有部署网站环境的情况下,配置这个文件可以让网站运行
开发规范
- 目录 只是小写字母和下划线构成
- 类的文件名以命名空间定义,并且命名空间和类库文件所在路径一致。
- 类的文件采用驼峰,并且首字母大写,其余文件为小写加下划线。
- 类名和类文件名保持一致,采用驼峰命名,首字母大写。
- 函数使用驼峰命名,首字母小写。
- 属性名采用驼峰,首字母小写
- 以双下划线开头的函数或方法为魔术方法。
- 常量以大写字母和下划线命名
- 表和字段必须以小写字母和下划线命名方式,不能以下划线开头。
apache配置根目录
<VirtualHost _default_:80>
DocumentRoot "C:\phpStudy\PHPTutorial\WWW\public"
ServerName localhost
ServerAlias localhost
<Directory "C:\phpStudy\PHPTutorial\WWW\public">
#下面被注释的代码,用“localhost”访问时会禁止访问
#Options -Indexes -FollowSymLinks +ExecCGI
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\phpStudy\PHPTutorial\WWW\public"
ServerName www.gohosts.com
ServerAlias gohosts.com
<Directory "C:\phpStudy\PHPTutorial\WWW\public">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
apache配置伪静态
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>
iis配置伪静态
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="cms">
<match url="^cms/(.*)$" />
<action type="Rewrite" url="/public/cms/pages/{R:1}" />
</rule>
<rule name="OrgPage" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/public/index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
关于TP5相关解决问题有哪些就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。