A number of projects have been developed with thinkphp; recently prepared to take time to write some experience summary;
Hope to be able to start contact with the TP children's shoes to provide some development programs, less to take some detours, less trample some pits;
These are absolutely the essence of dry goods; read with patience; believe in receiving large;
Can be combined with a GIT project-controlled study: Http://git.oschina.net/shuaibai123/thinkphp-bjyadmin
Let's start with the thinkphp directory architecture.
thinkbjy Bai Jun Haruka blog ├─application Project logical directory │ ├─common public module │ │ ├─common Common Functions Directory │ │ │ ├─functioin.php common functions php file │ │ ├─Conf configuration of Public profile directory │  │  │  ├─CONFIG.PHP  TP Used to override framework default configuration items │ │ │ ├─db.php Database configuration user name password │ │ │ ├─webconfig.php project configuration, website name, whether to open the website, etc. │ │ ├─controller Public Controller Catalog │ │ │ ├─BaseController.class.php apply the most basic controller │ │ │ ├─homebasecontroller.class.php home Base Controller Inheritance basecontroller│ │ │ ├─adminbasecontroller.class.php admin Base Controller Inheritance basecontroller│ │ │ ├─userbasecontroller.class.php user Base Controller Inheritance basecontroller│ │ │ ├─ ... │ │ ├─model Public Model Catalog │ │ │ ├─basemodel.class.php application of the most basic model│ │ │ ├─articlemodel.class.php Article model inheritance basemodel│ │ │ ├─usermodel.class.php User model inherit basemodel│ │ │ ├─ ... │ │ ├─tag Public Label Directory │ │ │ ├─my.class.php Custom Tag Library │ │ │ ├─ ... │ ├─home home Module │ │ ├─controller home Controller directory Inherit homebasecontroller│ │ │ ├─articlecontroller.class.php article Controller directory │ │ │ ├─IndexController.class.php Home Controller │ │ │ ├─ ... │ ├─Admin structure with home│ ├─user structure with home├─public resource file directory│ ├─install Installing the Boot directory │ ├─statics Static Resource Directory │ │ ├─bootstrap bootstrap Framework │ │ ├─ueditor ueditor Editor │ │ ├─js jquery and other third-party JS storage directory │ │ ├─css Animate.css and other third-party CSS directory │ │ ├─ ... ├─template View Files directory │ ├─public Common directory │ │ ├─js common JS directory │ │ │ ├─base.js all stations quoted JS file │ │ │ ├─ ... │ │ ├─css Public CSS Catalog │ │ │ ├─base.css All site referenced css file │ │ │ ├─ ... │ │ ├─images Public Picture Catalogue │ │ ├─public_head.html Common head │ │ ├─public_foot.html for all stations Universal Common bottom │ │ ├─... │ ├─home Reception Home View Catalog │ │ ├─Public Public directory │ │ │ ├─js of front desk home home reduced use of JS file directory │ │ │ ├─css home down the CSS file directory │ │ │ ├─images home reduced image file directory │ │ ├─index Home file directory │ │ │ ├─index.html home │ │ │  ├─&NBSP, ..... │ ├─admin and home│ ├─user with home├─upload public upload directory │ ├─images uploaded picture catalogue │ │ ├─avatar Avatar Directory │ │ ├─ueditor ueditor editor uploaded picture directory │ │ │ │  │&NBSP, ..... ├─runtime run-time directory ├─THINKPHP  Framework System directory
/application/common/common/function.php this as a common common function file;
Custom functions often used in the usual can be put inside;
For example, a previously written p function prints php arrays in a way that fits human reading.
Then also proposed to write: To determine whether the user login function, get the current login user ID function, upload function, image processing function, verification code function, paging function and so on;
/application/common/conf Public configuration item I recommend that you create at least the following 3 files
config.php, db.php, webconfig.php Why create 3 configuration item files? Let me explain in detail the role of these three documents;
Config.php inside are all system configuration items; This file is mainly used to overwrite the default configuration of the framework; This file is well understood;
db.php the account password of the database, etc., put a file separately because many times, this file needs to be completed according to the application installation of the database account password generated files;
webconfig.php The reason why the document is independent;
/application/common/controller Public Controller Directory
This directory must be built a BaseController.class.php in order to develop and maintain the convenience of our development to avoid changing the framework of the file;
Therefore, in order not to change the framework of the Controller.class.php we build a basecontroller after all the controller has inherited it;
So long as the method is written in the Basecontroller, all the controllers are inherited;
However, the projects we develop may be more complex, and only one basecontroller will be cluttered, so we can also build AdminBaseController.class.php based on business requirements. The construct constructor determines if it is not an administrator; we only need all the controllers that need to have administrator privileges to inherit Adminbasecontroller, so that these controllers do not need to judge whether they are administrators;
Specifically can see Thinkphp Integration series of RBAC of the upgraded version Auth Rights Management System demo
UserBaseController.class.php and other Xxbasecontroller the same reason, for example, the user's personal center must be logged in the state to access and so on;
/application/common/model Public Model Catalog
This directory must be built a BaseModel.class.php for what?
Balabala ...
Balabala ...
Well, when I was organizing the language, I found the more I wrote, so I was going to open a separate article to write the Basemodel question;
Portal: A summary of the design experience of model models for thinkphp
/application/common/tag Public Label Directory
For the convenience of development, we still have to build a custom tag library; My.class.php
What is a tag library? We will find that in the template TP built in a lot of tags very useful, such as foreach, Volist, eq;
Official Document Portal: Built-in label
What the? Don't know how to customize tags? All right, one more Portal: thinkphp Custom Template Tags
/public Resource File directory
Boostrap, jquery and other third-party plug-ins can be thrown into this area
/template View Catalog
It is recommended to move the view of each module to this directory for centralized management; otherwise, the various point directory switch when developing;
/template/default/home/public/js/base.js and/TEMPLATE/DEFAULT/HOME/PUBLIC/CSS/BASE.CSS strongly recommend that all stations be quoted; write some styles or functions that can be used all over the station. , such as the reset of the CSS, the other look at the above table of contents can be seen, not more wordy;
/runtime Run-time directory
As with the template, the recommendations are moved to the outermost layer, so we can delete the cache;
Well, it's really time-consuming to write a blog, and this blog has been written for a full 3 hours; I wish I could help the children's shoes.
650) this.width=650, "alt=" Bai Jun Remote Blog "src=" http://www.baijunyao.com/Upload/image/ueditor/20160313/1457881396160579. PNG "title=" Bai Jun Haruka Blog "/>
This article for Bai Jun Remote original article, reprinted without contact with me, but please specify from Bai Jun remote blog http://www.baijunyao.com
A summary of thinkphp's experience in directory structure design