thinkphp Study notes (ii)

Source: Internet
Author: User
Tags sqlite

1. Naming conventions

The following naming conventions should be followed as far as possible during development with thinkphp:

Class 2 files are suffixed with. class.php (this refers to the class library file used internally by thinkphp, which does not represent an externally loaded class library file), named with the Hump method, and capitalized, such as DbMysql.class.php;

2 Ensure that file naming and invocation are case-sensitive because of the sensitivity of the case to the Unix-like system (and thinkphp under debug mode, even if the Windows platform is heavily checked for capitalization);

2 The class name and file name are the same (including the same capitalization), for example, the file name of the Useraction class is UserAction.class.php, and the Infomodel class name is InfoModel.class.php, and the class name of different class library has certain specification;

2 other class library files, such as functions, configuration files, and so on, are usually suffixed with. PHP (third party not required);

2 the naming of functions uses lowercase letters and underscores, such as GET_CLIENT_IP;

2 methods are named using the Hump method, and the first letter lowercase or use underscore "_", such as getusername,_parsetype, usually the method that begins with an underscore belongs to the private method;

2 properties are named using the Hump method, and the first letter lowercase or use underscore "_", such as TableName, _instance, usually the underscore property belongs to the private property;

2 A function or method that begins with a double underscore "__" as a magical method, such as __call and __autoload;

2 constants are named with uppercase letters and underscores, such as Has_one and Many_to_many;

2 Configuration and under parameters in uppercase letters the name of the underline, e.g. html_cache_on;

2 language variables are named in uppercase letters and underscores, such as My_lang, where a language variable that starts with an underscore is usually used for system language variables, such as _class_not_exist_;

2 There is no mandatory specification for the naming of variables, which can be carried out according to the team specification;

2 the thinkphp template file is suffixed with. html By default (can be modified by configuration);

2 data tables and fields are named in lowercase and underlined , and note that field names do not start with an underscore , such as the Think_user table and the User_name field, similar to _username Such data table fields may be filtered.

Exception: In thinkphp , there is a special case of a function name, which is a single-letter capitalization function , which is usually a shortcut to some operations, or a special function.

thinkphp UTF-8 encoding is used by default, so make sure that your program files are saved in UTF-8 encoded format and that the BOM header is removed (There are many ways to get rid of BOM header information, different editors have a setup method, you can use tools for unified detection and processing), otherwise it may lead to many unexpected problems.

2.MVC tiering

The MVC hierarchy in thinkphp is broadly reflected in:

model (M): the definition of a model is done by the models class.

Controller (C): Application Controller (core Controller app Class) and action controller both assume the role of the Controller, the action controller completes the business Process control, and the application controller is responsible for scheduling control.

View (V): Composed of the view class and template files, the template is 100% separated and can be previewed and produced independently.

Sometimes, thinkphp does not depend on M or V, which means that no model or view can work. It doesn't even depend on C, because Thinkphp has a master controller on the action, the app Controller, which is responsible for the overall scheduling of the application. In the absence of C, there must be a view V, otherwise it is no longer a complete application.

3.CBD Architecture

The ThinkPHP3.0 version introduces the new CBD ( core core+ behavior behavior+ driven driver) architecture pattern, since the framework uses core + behavior + driven architecture from the ground up, and the core retains the most critical part, And in the important position of the label to mark, and other functions are the behavior extension and the combination of driving, the developer can according to their own needs, a label location to expand or replace the behavior can be convenient to customize the framework of the bottom, you can also add their own label location and add application lines at the application layer.

4. Features Overview

Recommended features include:

2 CBD Architecture: The ThinkPHP3.0 version introduces a new CBD (core + behavior + Drive) architecture model that builds the framework's bottom-up DIY and class-AOP programming experience. With this new feature, developers can easily customize a development framework for themselves or their business through pattern extensions.

2 compilation mechanism : Original project compiling mechanism, effectively reduce the performance cost of file loading in OOP development. Improved project compilation mechanism, can support the compilation file directly as a portal loading, and support the constant external loading, conducive to product release.

2 Class Library Import : Importing class libraries based on class library packages and namespaces makes the class library import look simpler and clearer, and also supports automatic loading and alias import. To facilitate cross-platform porting of the project, the system can also strictly check the case of the loaded file.

2 URLs and Routes : The system supports normal mode, pathinfo mode, rewrite mode and the URL mode of compatibility mode, support different server and operation mode deployment, with URL routing function, let you build the desired URL address and SEO optimization work. Support for flexible, rule-routed Ha Zheng Routing and Routing redirection support provides developers with a more convenient and flexible URL optimization experience.

2 Debug Mode: the debug mode provided by the framework can be easily used in different stages of the development process, including any need for development, testing, and presentation, and different application patterns can be configured with separate project profiles. Just a small performance sacrifice can meet the logging and analysis needs of debugging development and ensure a smooth future deployment, which can quickly improve performance once you switch to deployment mode.

2 ORM : Easy and lightweight ORM implementation, with simple curd and AR mode, make development efficiency everywhere.

2 database: support includes databases such as MySQL, Sqlite, pgsql, Oracle, SQL Server, MONGO, and a built-in distributed database and read/write separation feature support. The system supports multiple database connections and dynamic switching mechanisms, as a razor for enterprise development, with no worry about cross-database applications and distributed support.

2 Query Language : Built-in rich query mechanism, including combination query, quick query, compound query, interval query, statistical query, location query, multi-table query, sub-query, dynamic query and native query, make your data query concise and efficient.

2 dynamic models : No need to create any corresponding model classes, easy to complete the curd operation, support a variety of dynamic switch between models, let you enjoy the data operation of the incomparable and best experience.

2 extending the model : Provides a rich extension model, including: Support serialization fields, text fields, read-only fields, deferred write, optimistic lock, data table and other advanced features of advanced models; You can easily dynamically create a view model of a database view; an association model that supports associated operations Support MONGO database MONGO model and so on, all can be conveniently used.

2 module grouping : Don't worry about the coordination and deployment of major projects, grouping helps you solve cross-project challenges, and supports deployment support for two-level domain names in groups.

2 template engine : An excellent XML-based, compiled template engine is built into the system, supporting two types of template tags, incorporating the ideas of the Smarty and JSP tag libraries, and built-in layout template capabilities and tag Library extension support. Drivers can also support other third-party template engines such as Smarty, Easetemplate, Templatelite, and Smart.

2Ajax support : Built-in and client-independent AJAX data return methods that support JSON, XML, and eval types back to the client, and can extend the return data format, the system does not bind any Ajax class library, you can freely use their familiar Ajax class library to operate.

2SAE support: provides strong support for the Sina SAE platform, with "spanning" and "smoothness", support for localization development and commissioning, and deployment switching, allowing you to easily transition to SAE development and create a new SAE development experience.

2restful support: Rest mode provides restful support for you to create a new URL design and access experience, while providing support for interface applications.

2 Multi-lingual support : The system supports language pack features, projects and groupings can have separate language packs, and automatic loading of corresponding language packs can be automatically detected in the browser language.

2 mode expansion : In addition to the standard mode, AMF, PHPRPC, Lite, thin, and CLI mode extension support are available, providing the best core framework for different levels of application development, as well as custom schema extensions.

2 automatic verification and completion : Automatic verification and filtering of form data, additional authentication methods such as IP authentication and validity period verification, new version, and automatic completion can generate secure data objects.

2 field type detection : The system automatically caches field information and field types, supports illegal field filtering and field type casts, and ensures more secure data writes and queries.

2 caching mechanism : The system supports Dynamic Data cache types including file mode, APC, Db, Memcache, Shmop, Sqlite, Redis, Eaccelerator and XCache, as well as customizable static cache rules, and provides a quick way to access operations.

2 extension mechanism : The system supports a powerful and flexible extension mechanism including pattern extension, behavior extension, class Library extension, driver extension, Model extension, Controller extension, widget extension, so that you are no longer limited to the core of the shortcomings and the confusion, DIY your own framework and expand the application, Meet the needs of more complex projects in enterprise development.

5. Development process

The general development process for creating an app using thinkphp is:

System design, database creation and data tables; (optional)

project naming and creating Build Project Entry file, open debug mode;

Complete the project configuration;

Create a project function library; (optional)

Expansion required for development projects (modes, drivers, tag libraries, etc.); (optional)

Create a controller class;

Create a model class; (optional)

Create template files;

Run and debug and analyze logs;

Develop and set up caching capabilities; (optional)

Add routing support; (optional)

Security checks; (optional)

Deploy to a production environment.



This article is from the "Little Prince" blog, please be sure to keep this source http://littleprince.blog.51cto.com/1491292/1617815

thinkphp Study notes (ii)

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.