thinkphp 3.2.3 (iii) Modular design of architecture

Source: Internet
Author: User

first, the concept application:Projects that are accessed based on the same portal file are called an Application. module:An application can contain multiple modules, each of which is a separate subdirectory under the application directory, and is a collection of configuration files, function files, and MVC files (directories). controller:Each module can contain multiple controllers, and a controller typically manifests itself as a controller class. operation:Each controller class can contain more than one action method, or it may be a binding action class, with each operation being the smallest unit of URL access. ii. Typical URL access ruleshttp://serverName/index.php (or Other Application entry File)/module/controller/operation/[parameter Name/parameter value ...] third, the module designAn application directory below the module directory structure is as follows, each module can be easily uninstalled and deployed, and support public modules. The module can be accessed as long as the module directory exists under the application Directory.            Application default app directory (can be set) ├─common public module (not directly accessible) ├─home foreground module ├─admin backend module ├─ ... Additional modules ├─runtime Default runtime directory (can be set) each module is relatively independent, and its directory structure is as follows: ├─module module directory │├─conf configuration file directory │├─common number of public functions Catalogue │├─controller Controller Directory │├─model model catalog │├─logic logical directory (optional) │├─service Service directory (optional) │ ... More Hierarchical catalogs optional │└─view view catalog iv. Public Module CommonThe common module itself cannot be accessed directly through a url, and other files of the public module can be inherited or invoked by other Modules.the manual says that access to all modules will first load the public module under the configuration file ( Conf/config.php ) and the public function file ( Common/function.php ), But the function.php file is not found. the manual says that the location of the public module can be changed by defining the Common_path constant in the portal file . define (' common_path ', './common/'); when the constant is defined in the portal file, its application directory structure becomes:www Web Deployment directory (or subdirectory) ├─index.php portal file ├─readme.md README file ├─common after applying the common module directory//definition, the application directory does not Need common directory again ├─application application Module Directory ├─public application resource file directory └─thinkphp Framework Directory in practice, however, The directory structure does not change.   v. Automatically generate module catalogs1. Generate a module for example, if you need to generate an admin module for background applications, Define the following in the application Portal File://bind Admin module to current portal file
Define (' bind_module ', ' Admin ');
Define (' App_path ', './application/');
Require './thinkphp/thinkphp.php '; then access the portal file http://localhost/ThinkPHP-3.2.3/index.php, generate the directory of the admin module and generate a default controller class Admin\Controller\IndexController。 This time to visit http://localhost/ThinkPHP-3.2.3/index.php/home/index/index, error: you need to delete or comment out the statement define (' bind_module ', ' Admin ') defined by that constant to access the home module normally.   also found a problem:When the module directory is automatically generated, define (' bind_module ', ' Admin '); The statement is placed on require './thinkphp/thinkphp.php '; otherwise, the module will not be Generated. Binding the Admin module to the current portal file
Define (' bind_module ', ' Admin ');
Define (' app_path ', './application/'); require './thinkphp/thinkphp.php '; after build, access http://localhost/ThinkPHP-3.2.3/ index.php no problem, the admin module is the default "welcome to thinkphp page". But access to Http://localhost/ThinkPHP-3.2.3/index.php/Admin/Index/index will be an Error. the Define (' bind_module ', ' Admin ') needs to be placed in the Require './thinkphp/thinkphp.php '; 2. Generate multiple controller classes and model classes if you need to generate more controller classes, you can define BUILD_CONTROLLER_LISTconstants, such as://bind the Admin module to the current entry file define (' bind_module ', ' Admin ');d efine (' build_controller_list ', ' Index,user,menu '); The model class is Build_model_listdefine (' app_path ', './application/'); require './thinkphp/thinkphp.php '; issue 1: the control class as described in the manual is not generated after accessAdmin\controller\indexcontroller
Admin\controller\usercontrolleradmin\controller\menucontroller question 2: After the thinkphp framework is re-built, the first access to the portal file becomes a plurality of control classes, but the other control classes will still Fail. Baidu has this problem, someone has also encountered similar problems with me, the workaround is to create the module and the corresponding control classes by removing the generated module and then re-accessing the portal File.  3. Manual generation of controller classes and model classes manually called Think\Buildclass to generate the controller class and model class, for Example://generate Admin Module for role controller class or model Class//default class library for Admin\controller\rolecontroller        or Admin\model\rolemodel//will not regenerate \think\build::buildcontroller (' Admin ', ' Role ') if it already exists; or \think\build::buildmodel (' Admin ', ' Role '); error: Fatal Error: Class ' think\build ' not found in D:\xampp\htdocs\ThinkPHP-3.2.3\index.phpOn line - when you debug, you find:The statement calling the method in the Think\build class should be placed in the reference thinkphp Portal file statement (require './thinkphp/thinkphp.php '; ) below. The method of calling the Think\build class can also be written as: require './thinkphp/thinkphp.php '; Include './thinkphp/library/think/build.class.php '; $build = new \think\build (); $build->buildcontroller (' Admin ', ' Role '); vi. Disable access to modulesAccess is forbidden in the default configuration CommonModules and RuntimeModule (runtime directory is the default runtime directory).The manual says that you can add additional blocks to the list of blocked access Modules:Set the list of forbidden modules ' module_deny_list ' = = array (' Common ', ' Runtime ', ' API '), after setting, the API module cannot be accessed directly via the Url. I don't know at first whether this configuration needs to be defined in the portal file or in the config.php file under application/common/conf, and later in/thinkphp/conf/ This configuration was found in the convention.php file. Add your own generated admin module, access to http://localhost/ThinkPHP-3.2.3/index.php/Admin/Index/index, unable to load the admin module, indicating that the block access module is Successful. vii. Setting up access listsIf fewer modules are applied, you can also set the Allow access list and the default module, which simplifies URL access to the default Module. ' module_allow_list ' = = array (' Home ', ' admin ', ' user '), ' default_module ' = ' home ', after setting, except Home, admin and User module Modules are not directly accessible, and the home module is the default Access module (which may not appear at the URL address).the above is the manual, but this configuration seems to be useless? And what is the so-called direct access? and in the/thinkphp/conf/convention.php file, module_allow_list is not found in this Configuration. once the module is built, direct access to http://localhost/ThinkPHP-3.2.3/home (or Admin or User) is Accessible. eight, Single module designChange the Multi_module in the/thinkphp/conf/convention.php file from True to false, and if false, you must set the Default_module. Turn off multi-module access ' multi_module ' and false, ' default_module ' = ' home ', Once you turn off Multi-module access, You can only access the default module (Home is set here). problem: URLs are only accessible for http://localhost/ThinkPHP-3.2.3/index.php, other forms such as http://localhost/ThinkPHP-3.2.3/index.php/ Neither home nor Http://localhost/ThinkPHP-3.2.3/index.php/home/index/index can be accessed in any way. nine, multi-entrance DesignYou can set up multiple portals for the same application and modules, and different entry files can be configured with different application modes or binding Modules. For example, in index.phpThe File's sibling directory adds a admin.phpPortal file, and bind admin module://bind Admin module to current entry file define (' bind_module ', ' admin ');
Define (' app_path ', './application/'); require './thinkphp/thinkphp.php '; original access address http://localhost/ThinkPHP-3.2.3/ Index.php/admin/index/index can be changed to HTTP://LOCALHOST/THINKPHP-3.2.3/ admin.php/index/index. similarly, bind index.php to the Home Module's original access address Http://localhost/ThinkPHP-3.2.3/index.php/Home/Index/index can be changed to HTTP://LOCALHOST/THINKPHP-3.2.3/ home.php/index/index. Internal Server Error Appears:This is because the index.php file has not been renamed, and will be accessed normally after renaming to Home.php.

thinkphp 3.2.3 (iii) Modular design of architecture

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.