在Common -> Conf文件夹下新建一个systemConfig.php和config.php

systemConfig">

Home Backend Development PHP Tutorial 生手搭建ThinkPHP框架

生手搭建ThinkPHP框架

Jun 13, 2016 pm 12:23 PM
gt public system thinkphp

新手搭建ThinkPHP框架

分享知识 传递快乐


代码比较简单,很可能出现各种Bug,但可以满足初级用户,如有提议或更好的方法请留言--分享知识 传递快乐。


提示:首先确定部署的ThinkPHP框架能运行(ThinkPHP3.2.3)。


首先在ThinkPHP框架的根目录下新建一个admin.php,

代码如下

PHP:

<?php // 后台应用入口文件// 检测PHP环境if(version_compare(PHP_VERSION,&#39;5.3.0&#39;,&#39;<&#39;))  die(&#39;require PHP > 5.3.0 !');// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为falsedefine('APP_DEBUG',True);//绑定并生成后台目录。define('BIND_MODULE','Admin');// 定义应用目录define('APP_PATH','./Application/');// 引入ThinkPHP入口文件require './ThinkPHP/ThinkPHP.php';// 亲^_^ 后面不需要任何代码了 就是如此简单
Copy after login


ThinkPHP会自动生成以下目录:



在Common -> Conf文件夹下新建一个systemConfig.php和config.php

systemConfig.php:

<?php $public_system_db_host = &#39;127.0.0.1&#39;;$public_system_db_name = &#39;&#39;;//数据库名字$public_system_db_user = &#39;root&#39;;//数据库账号$public_system_db_pwd = &#39;&#39;;//数据库密码return array(    &#39;DB_HOST&#39;=> $public_system_db_host, // 数据库服务器地址    'DB_NAME'=> $public_system_db_name,  // 数据库名称    'DB_USER'=> $public_system_db_user, // 数据库用户名    'DB_PWD'=> $public_system_db_pwd, // 数据库密码    'DB_PORT'=>'3306', // 数据库端口    'DB_PREFIX'=>'cj_', // 数据表前缀);
Copy after login


config.php

<?phpreturn array(    /* 数据库设置 */    &#39;DB_TYPE&#39; => 'mysql', // 数据库类型    'TOKEN_ON' => true, // 是否开启令牌验证    'TOKEN_TYPE' => 'md5', //令牌哈希验证规则 默认为MD5    'TOKEN_RESET' => FALSE, //令牌验证出错后是否重置令牌 默认为true    'LOAD_EXT_CONFIG' => 'systemConfig',    'DEFAULT_C_LAYER'       =>  'Controller', // 默认的控制器层名称    'MODULE_ALLOW_LIST'     =>  array('Home','s'), // 配置你原来的分组列表    'DEFAULT_MODULE'        =>  'Home', // 配置你原来的默认分组    'URL_ROUTER_ON'   => true,);
Copy after login


这时再在Controller下的默认Controller里就可以对数据库操作了。

代码如下:

<span style="font-size:18px;"><?phpnamespace Admin\Controller;use Think\Controller;class IndexController extends Controller {    public function index(){        $this->display();    }    public function showDate(){        $table = M("表名");        $list = $table->select();        echo json_encode($list);    }}</span>
Copy after login


代码比较简单,初级用户可以参考,



版权声明:本文为博主原创文章,未经博主允许不得转载。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

Java documentation interpretation: Usage analysis of the currentTimeMillis() method of the System class Java documentation interpretation: Usage analysis of the currentTimeMillis() method of the System class Nov 03, 2023 am 09:30 AM

Java document interpretation: Usage analysis of the currentTimeMillis() method of the System class, specific code examples are required. In Java programming, the System class is a very important class, which encapsulates some properties and operations related to the system. Among them, the currentTimeMillis method is a very commonly used method in the System class. This article will explain the method in detail and provide code examples. 1. Overview of currentTimeMillis method

What is the difference between the developer version and the public version of iOS? What is the difference between the developer version and the public version of iOS? Mar 01, 2024 pm 12:55 PM

Every year before Apple releases a new major version of iOS and macOS, users can download the beta version several months in advance and experience it first. Since the software is used by both the public and developers, Apple has launched developer and public versions, which are public beta versions of the developer beta version, for both. What is the difference between the developer version and the public version of iOS? Literally speaking, the developer version is a developer test version, and the public version is a public test version. The developer version and the public version target different audiences. The developer version is used by Apple for testing by developers. You need an Apple developer account to download and upgrade it.

See all articles