001thinkphp Development Environment Construction

Source: Internet
Author: User

thinkphp3.1 (including 3.1) requires PHP5.2 (including 5.2) of the following version, if 5.3 (including 5.3) of the version will cause the MySQL statement error.
thinkphp3.2 must be in PHP5.3 (including 5.3) and above (note: Php5.3dev version and PHP6 are not supported), otherwise it will not work

Based on ThinkPHP3.2 Learning, please refer to: http://document.thinkphp.cn/manual_3_2.html

This document is only for the ThinkPHP3.2 document to see the problem, to solve the problem to be solved should also be no problem. The basic configuration will not be described.

The directory structure of the above application is only the default setting, in fact, when actually deploying the application, we recommend that in addition to the application portal file and Public resource directory, other files are placed under the non-web directory, with better security.

Configuration of portal file configuration, database connection, etc.?

When the project starts, the default welcome page is displayed when the application portal file is first accessed, and a default application module home is generated automatically.

Next look at the original empty Application directory below, has automatically generated the public module Common , the default Home module and Runtime The directory structure of the runtime directory:

Application
├─common Application Public Module
│├─common Apply Public Function directory
│└─CONF Application Public Profile Directory
├─home Default generated Home module
│├─CONF Module Configuration file directory
│├─common module Functions Public directory
│├─controller Module Controller Directory
│├─model Module Model Catalog
│└─view Module View File directory
├─runtime Run-time directory
│├─cache Template Cache Directory
│├─data Data Catalog
│├─logs Log Directory
│└─temp Cache Directory

Directory Security files

While the directory structure is automatically generated, we also see the index.html file under each directory, which is the thinkphp automatically generated directory security file.

In order to avoid some servers to open the Directory browsing permissions can be directly in the browser input URL address to view the directory, the system by default, the directory security file mechanism, will be automatically generated when the directory generated blank index.html files, of course, the name of the security file can be set, for example, you want to define the security file as default.html You can add the following in the portal file:

Define (' Dir_secure_filename ', ' default.html '); Define (' App_path ', './application/'); require './thinkphp/thinkphp.php ';

If your environment is secure enough that you do not want to generate directory-safe files, you can turn off the creation of directory-safe files inside the portal file, for example:

Define false);

Remember, the test looks at the specific effect

The concept of modules

Typically 3.2 does not need to use multi-application mode, because in most cases, we can solve the application expansion requirements through multi-modular and multi-entry design.

We can find a file under the auto-generated Application/home/controller directory IndexController.class.php , which is the default index controller file.

The controller class is named by: Controller name (hump method, first letter capitalization) +controller

Controller files are named by: Class name +class.php (class file suffix)

The default welcome page is actually the index action method of the index controller class under the home module that we are accessing, we modify the default index action method as follows:

namespace Home\controller;  Use Think\controller; class extends Controller {    publicfunction  index () {        echo ' Hello, world! ' ;    }}

Run the app portal file again and the browser will display: hello,world! .

. class.php suffix of the background class file, how to correspond with the foreground file, access to the foreground file and how to achieve the interaction between front and back

Let's look at the controller class, the beginning of the Indexcontroller controller class is the namespace definition:

namespace Home\controller;

This is the system's specification requirements, indicating that the current class is the Controller class under the Home module, the namespace and the actual controller file is located in the same path, that is, the Home\Controller\IndexController class corresponding controller file is located under the application directory

Home/Controller/IndexController.class.php, if you change the current module name, then the namespace of the Controller class needs to be modified as well.

Note: The namespace definition must be written before all PHP code is declared, otherwise an error will occur

 Use Think\controller;


Indicates that the introduction of the Think\controller namespace facilitates direct use. So

 Use Think\controller; class extends Controller

Equivalent to using:
class extends \think\controller

Development recommendations

In the process of developing with thinkphp, we offer the following recommendations that will make your development easier:

    • Follow the framework's naming conventions and catalog specifications;
    • In the development process as far as possible to open debugging mode, early detection problems;
    • Look at the log files to find hidden problems;
    • Develop a good habit of using the I function to get input variables;
    • After updating or environment change, the first problem is emptying the runtime directory;

001thinkphp Development Environment Construction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.