The easiest-to-operate ThinkPHP framework in history (share)
下面由thinkphp框架教程栏目给大家介绍史上最简单操作的ThinkPHP 框架(分享),希望对需要的朋友有所帮助!
配1)文件设置;
//定义了配置文件之后,可以使用系统提供的C方法(如果觉得比较奇怪的话,可以借助Config单词来帮助记忆)来读取已有的配置:
C('参数名称')//获取已经设置的参数值
echo C('APP_PATH'); // -------- 入口文件配置 -------- define('APP_DEBUG', true); //应用调试模式 (默认为false),开启后会缓存 define('APP_NAME', 'App'); define('APP_PATH', './App/'); require('./ThinkPHP/ThinkPHP.php');
// -------- 自定义配置文件不受 APP_DEBUG 控制,每次都会加载 --------
项目配置文件是最常用的配置文件,项目配置文件位于项目的配置文件目录Conf下面,文件名是config.php。
除了默认的项目配置文件,还允许我们在该目录下自行设置自定义配置文件,且该自定义配置文件不受APP_DEBUG配置影响,修改内容后都会重新加载到模板中。(设置该自定义配置文件,需要先在 config.php 里面配置 'LOAD_EXT_CONFIG'=>'XXX')
2) URL模式;
// 为了配合所使用的URL模式,我们需要能够动态的根据当前的URL设置生成对应的URL地址,为此,ThinkPHP内置提供了U方法,用于URL的动态生成,可以确保项目在移植过程中不受环境的影响。 // U方法的定义规则如下(方括号内参数根据实际应用决定): U('[分组/模块/操作]?参数' [,'参数','伪静态后缀','是否跳转','显示域名']) echo U('Index/hello', array('id'=>2), 'html', false, '192.168.2.110'); //普通模式:设置URL_MODEL 为0 http://192.168.2.110/thinkphp3/index.php?m=Index&a=hello&id=2 //PATHINFO模式(默认模式):设置URL_MODEL 为1 http://192.168.2.110/thinkphp3/index.php/Index/hello/id/2.html
3) 隐藏index.php运行文件;
// 进入Apache配置文件htppd.conf vim /etc/httpd/conf/httpd.conf // 在命令模式下输入 "/LoadModule" 进行查找, 模仿Example,在其后面加上 LoadModule rewrite_module modules/mod_rewrite.so // 保存 :wq 后重启Apache服务器 systemctl restart httpd.service // 在项目入口文件 index.php 的同级目录下添加 .htaccess 文件,添加如下内容 <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule> // 此时,访问ThinkPHP的REWRITE模式可以成功连接
4) URL伪静态;
// ThinkPHP支持伪静态URL设置,可以通过设置 URL_HTML_SUFFIX 参数随意在URL的最后增加你想要的静态后缀,而不会影响当前操作的正常执行; // 如果只是希望支持配置的伪静态后缀,可以直接设置成可以支持多个后缀,例如: 'URL_HTML_SUFFIX'=>'html|shmtl|xml' // 多个用 | 分割 // 使用伪静态便于让爬虫爬到你的网站,对搜索到你的网站有帮助;
5) 自定义函数库;
// ThinkPHP可以在项目的 Common 文件夹增加自定义函数文件 common.php(该文件名是规定的),在里面设置方法,之后可以在其他文件调用,如: <?php function show() { echo 'hello world'; } // 推荐方法打印方法:dump $arr = array(1,2,3,4,5); dump($arr);
相关推荐:最新的10个thinkphp视频教程
The above is the detailed content of The easiest-to-operate ThinkPHP framework in history (share). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

ThinkPHP6 routing parameters are processed in Chinese and complete acquisition. In the ThinkPHP6 framework, URL parameters containing special characters (such as Chinese and punctuation marks) are often processed...

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

Using the ThinkPHP6 framework combined with elasticsearch-php client to operate Elasticsearch...

Comparison of Redis queues and MySQL stability: Why is Redis prone to data loss? In the development environment, using PHP7.2 and ThinkPHP frameworks, we often face the choice of cooperation...

ThinkPHP6 database query: How to use TP6 to implement SQL statements SELECTSUM(jin), SUM(chu)FROMsysdbuil In ThinkPHP6 framework, how to use SQL statement SELECT...
