Home >Backend Development >PHP Tutorial >Installation and configuration of thinkphp for beginners

Installation and configuration of thinkphp for beginners

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-28 08:28:261072browse

ThinkPHP--Installation and configuration
Learning points:
1. Obtain ThinkPHP
2. Entry file
3. Automatically generate
4. Access controller
ThinkPHP is a free and open source framework, based on the MVC design pattern and object-oriented development.
1. To obtain ThinkPHP
, we directly log in to the ThinkPHP official website download channel: http://www.thinkphp.cn/down.html, and select the latest official full version of ThinkPHP3.2.1.
Since the latest version adopts new features such as namespaces, the framework’s minimum requirement for PHP version is 5.3+.
Other requirements are generally supported, and we can meet all requirements directly by using wamp.
Unzip ThinkPHP3.2.1, open it or import it into the project, expand six files and folders:
Application -- application directory, automatically generated when the program is developed, empty by default;
Public -- public resource file directory , stores some public files, empty by default;
ThinkPHP -- framework directory, core architecture package of the framework;
README.md -- description file, can be deleted;
.htaccess -- configuration file, generally used to configure pseudo Static;
Index.php --entry file, all programs are accessed through here.
The ThinkPHP framework directory also contains a large number of directories and files:
Common -- core public function directory
Conf -- core configuration directory
Lang -- core language package directory
Library -- framework class library directory
|-- Think --Core Think class library package directory
|--Behavior --Behavior class library directory
|--Org --Org class library package directory
|--Vendor --Third-party class library directory
|--.. . --More class library directories
Mode --Framework application mode directory
Tpl --System template directory
LICENSE.txt --Framework authorization agreement file
logo.png --Framework LOGO file
README.txt --Framework README File
index.php --framework entry file
2. The entry file
ThinkPHP uses a single entry mode to deploy and access the project, so we need to do some deployment work through index.php
to ensure its correct access.
1. Copy the contents of the full version of the compressed package to the specified server folder, such as demo39;
2. Open the index.php file provided by ThinkPHP, and we find the following code:
//Detect PHP environment
if( version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP >
5.3.0 !');
//To enable debugging mode, it is recommended to enable deployment phase comments during the development phase or set it to false
define ('APP_DEBUG',True);
//Define the application directory
define('APP_PATH','./Application/');
//Introduce the ThinkPHP entry file
require './ThinkPHP/ThinkPHP.php';
3 .If you want to set the application directory name according to your own wishes, you can modify it like this:
//Modify the application directory
define('APP_PATH','./Weibo/');
//Modify the framework directory
require './Think /ThinkPHP.php';
When you run this configured application for the first time, a Weibo folder will be generated in the root directory, and all files of the application
program will be stored here.
Three. Automatically generated
When you access the application entry file for the first time, the Weibo application directory will be automatically generated. It contains
various directories, the descriptions are as follows:
Common -- application common module
| --Common -- application public function directory
| -- Conf -- application public configuration file directory
Home -- the default generated Home module
|--Conf --Module configuration file directory
|--Common --Module function public directory
|--Controller --Module controller directory
|--Model --Module model directory
|--View -- Module view file directory
Runtime --runtime directory
|--Cache --template cache directory
|--Data --data directory
|--Logs --log directory
|--Temp --cache directory
index .php has only one entry, which is the application entry. If there are multiple stations or backends, another entrance is needed.
Create an admin.php and change the application directory to the corresponding one.
//Modify the application directory
define('APP_PATH','./Admin/');
In the automatically generated directory, in order to prevent access to the directory structure of the application, an index.html file will be created. Of course, you can also set it yourself.
//Set the file generated by the directory
define('DIR_SECURE_FILENAME', 'default.html');
//Set the directory page content
define('DIR_SECURE_CONTENT', 'Directory prohibited');
Generally speaking, the first When generating an application, a static home page should be added to prevent the directory structure from being exposed. But if your environment is very secure, you can turn off generating static homepages.
//Disable directory homepage generation
define('BUILD_DIR_SECURE', false);
4. Access the controller
The controller path is under: Weibo/Home/Controller. There is a default controller IndexController.class.php
file.
The naming method of the controller class: controller name (camel case, first letter capitalized) + Controller
The naming method of the controller file: class name + class.php
Creating a controller requires three parts: 1. Set the namespace ; 2. Import the namespace; 3. Controller class
//Set the namespace
namespace HomeController; //Set the namespace, which is the current directory
//Import the namespace
use ThinkController; //Inherit the parent class and use the Controller class
//Controller class
class IndexController extends Controller {
public function index() {
//...
}
}
In addition to direct access to the homepage: http://localhost/demo39/, if you want to use the complete form, then Is:
http://localhost/demo39/index.php/Home/Index/index.
In the complete URL here, index.php is a single entry file, Home is the main module, Index is the name of the controller, and
index is a method in the controller. Note: This is case sensitive because Linux is case sensitive.
If you create a test() method, the URL is:
http://localhost/demo39/index.php/Home/Index/test
If you want to create a User module, you can create a User controller.
namespace HomeController;
use ThinkController;
class UserController extends Controller {
public function index() {
echo 'user';
}
}

URL access path is: http://localhost/demo39/index.php/ Home/User/index

demo39 is the root directory of the front-end website;

index.php is the entry file of the website;

Home is the module;

User is the controller;

index is the function in the user controller ( );


The above introduces the installation and configuration of thinkphp for beginners, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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