thinkphp framework foundation

零到壹度
Release: 2023-03-22 10:36:02
Original
1316 people have browsed it

This time I will bring you the basics of the thinkphp framework. What are the precautions for the thinkphp framework basics? The following is a practical case, let’s take a look.

l. Create a project, put all the files after decompression of the compressed package into the project, then configure the apach server, open the browser, output the URL 127.0.0.1, the page will prompt " Welcome to thinkphp", which means the application is successful.

1.Create the entry file

Then create a new folder under the project, for example, create a new student login System, it is recommended to create a new index.php in the student folder and introduce the Thinkphp.php file into it.

<?php  
 include &#39;../ThinkPHP/ThinkPHP.php&#39;;  
?>
Copy after login

Then visit the URL 127.0.0.1/student/index.php and "Welcome to thinkphp" will be displayed. At this time, you will find that there are several more folders in the directory you created. , common, component, Home, Runtime folders.

##2. Database connection

Let’s open Common first In this folder, open the Conf folder, there is a config.php file inside, and then open the file:

<?php
return array(
	//&#39;配置项&#39;=>&#39;配置值&#39;
	&#39;DB_TYPE&#39; => &#39;mysql&#39;, // 数据库类型
	&#39;DB_HOST&#39; => &#39;127.0.0.1&#39;, // 服务器地址
	&#39;DB_NAME&#39; => &#39;test&#39;, // 数据库名
	&#39;DB_USER&#39; => &#39;root&#39;, // 用户名
	&#39;DB_PWD&#39; => &#39;&#39;, // 密码
	&#39;DB_PORT&#39; => 3306, // 端口
	&#39;DB_PREFIX&#39; => &#39;s_&#39;, // 数据库表前缀
	&#39;DB_CHARSET&#39;=> &#39;utf8&#39;, // 字符集
	&#39;DB_DEBUG&#39; => TRUE, // 数据库调试模式 开启后可以记录SQL日志
	&#39;TMPL_TEMPLATE_SUFFIX&#39;  =>  &#39;.tpl&#39;,     // 默认模板文件后缀
	&#39;TMPL_L_DELIM&#39;          =>  &#39;<{&#39;,            // 模板引擎普通标签开始标记
        &#39;TMPL_R_DELIM&#39;          =>  &#39;}>&#39;,            // 模板引擎普通标签结束标记
        &#39;SHOW_PAGE_TRACE&#39; =>true,  //显示页面trace信息
    

);
Copy after login

This is the database configuration

3.After connecting to the database, let’s take a look at the core of the tp framework

The tp framework also uses the mainstream MVC Mode, open the Home folder, and you can see that Controller, Model, and View correspond to controllers, templates, and views respectively. I suggest that if you have not learned the MVC pattern well, you should learn MVC first and then learn the tp framework:

namespace Home\Controller;  
use Think\Controller;  
class IndexController extends Controller {  
 public function index(){  
        $Index = D(&#39;Index&#39;);  
        $info=$Index->select();  
        $this->assign(&#39;info&#39;, $info);  
        $this->display();  
    }  
}
Copy after login

As shown in the above code, the table name of the database is s_Index. You put the indicated prefix s_ in config.php and instantiate table D( ) function, in fact, it connects to the s_Index table of the database and then the query result is directly put into the $info "array" and then

{foreach $info as $k => $v}  
{$v.xxxx}  
{/foreach}
Copy after login

This loops out all the data in the xxxx field.

Summary: Although the tp framework is troublesome to configure and apply at the beginning, if you learn the MVC framework well and build a good template, the efficiency will be very high.

Related recommendations:

thinkphp hides index.php/home and allows access to other modules.

thinkphp Apache configuration restart Apache1 restart error solution

ThinkPHP template engine usage detailed explanation

The above is the detailed content of thinkphp framework foundation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!