Tag: Name member Thinksns project configuration class start API PHP file structure
In order to help the teacher with Thinksns two times to develop a micro-BO system, specifically spent a few days to learn thinkphp framework, now some thinkphp knowledge to record.
First, declare:
This article is not a complete tutorial, just to summarize the problems encountered in the development, if you need to learn thinkphp framework, please refer to the official website documentation:
Official homepage
ThinkPHP3.1 Quick Start tutorial (in Update)
thinkphp Full Development Handbook
ThinkPHP3.1 API Manual
Attached: Open source micro-blogging system Thinksns
Directory structure
Catalog/File |
Description |
thinkphp.php |
Frame Entry File |
Common |
Framework Common Files Directory |
Conf |
Framework configuration file Directory |
Lang |
Framework System Language Directory |
Lib |
System core base Class Library Directory |
Tpl |
System Templates Directory |
Extend |
Framework Extensions directory (for more information on extended directories, refer to the Extensions section later) |
My file structure
Entrance (thinkphp.php)
1, first in the Web root directory (I use the phpstudy, is the WWW folder) under the creation of an app project (this app is our project name).
2, will download the thinkphp decompression (I was extracted to the app, named Thinkphp).
3. Create a index.php file under the app directory and add two simple lines of code:
<?php
Define ("App_debug", TRUE); Open debug mode, easy to debug require '/thinkphp frame directory/thinkphp.php '; Mine is/thinkphp/thinkphp.php.
The purpose of this line of code is to load the thinkphp framework's Portal file thinkphp.php, which is the first step in all thinkphp-based development applications.
Then, access the portal file in the browser.
http://localhost/app/index.php
Because index.php is the default home page, it can also be omitted.
Template (TPL)
Under the TPL folder is the template page, you can place HTML, PHP and other pages.
Support multiple modules at the same time, you can create multiple folders under the TPL, each folder corresponds to a module, and a module and a controller corresponding (need the same name)
It's mine:
Two modules form, Index
There are two folders under the TPL form, Index
The corresponding controller is also two FormController.class.php, IndexController.class.php
Controllers (Controller)
Name: module name +controller
pathinfo mode : Is the system's default URL mode, provides the best SEO support, the system has done the environment compatible processing, so it can support the majority of host environment.
Corresponding to the URL pattern above, the URL access address under PathInfo mode is:
http://localhost/app/index.php/module/action/var/value/
Module name (controller name), without controller//action as operation name (method name in controller), parameter name//value without model//var as argument value
var and value appear in pairs
It's mine:
Http://localhost/app/index.php/Index/index
Call the index () method under Indexcontroller
If the method does not exist, the tpl/index/index.html page is called directly
Models (model)
1, naming: module name +model
In the thinkphp model, there are several attribute definitions for the name of the data table, declared in the corresponding model as attribute fields (or called member variables):
Properties |
Description |
TableName |
A data table name that does not contain a table prefix, typically the default is the same as the model name, which needs to be defined only if your table name differs from the name of the current model class. |
Truetablename |
The name of the data table that contains the prefix, which is the actual table name in the database, which does not need to be set, only if the above rules do not apply, or in special cases. |
DbName |
Define the database name that the model currently corresponds to, only if you have a different database name and configuration file for your current model class. |
As long as the naming specification, thinkphp will find the database table you want to call according to the model name, of course, if you have to build.
Rules:
1) The table name is Tp_categories (tp_ is the table prefix and is configured in the configuration file)
2) Table name Top_depts,top_ is not a system-configured table prefix, you need to use the full name of the table
3) can set the database
protected $dbName = ' top ';
Call:
You can call this module model, or it can be called across projects or modules.
This module:
D ("Usermodel")
Cross-project:
D ("Usermodel", "app")//d (model name, project name)
The M method is similar to the D method, but I only use the D method
function library
Available through load (@.hello), hello for function library file name
You can also define Load_ext_file parameters in the project configuration file, for example:
"Load_ext_file" = "user,db"
Class Library
Import allows you to introduce a class package that can be used across projects or modules
Import ("App.Model.UserModel");
App for application name model indicates model Usermodel
Database
This piece of stuff is too much, use also most frequently, therefore, the official document introduction is very detailed, please click on the link at the beginning of the article to view
Wrote for a long time, hope for everyone a little useful.
Original link: http://www.cnblogs.com/FlyFive/archive/2013/01/06/2848246.html
Preliminary mastery of thinkphp framework