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