Grape Dynamic PHP structure (i)--directory structure and configuration file

Source: Internet
Author: User
Tags autoload constant definition

First, the structure of the introduction

Structure of the name grape, Chinese name grape, because recently a colleague often brought grapes to our company to eat, was inspired to think of this name.

1) This structure needs to be run in PHP5.5, if it is to be run in 5.4 , some changes will be made in some places .

2) MongoDB is used in the structure, so additional references to Php_mongo are required in PHP. DLL file to View the installation method .

3) also used the Performance tool Xhprof, full-Text Search tool Coreseek(modified sphinx), if the use requires additional configuration, if not used can be closed

4) Integration of some API interfaces, click to view the " Public Platform development series "

5) Integrated Grape-skin (grape skin) static structure, as the management of the background page style and effects

6) Background Management demo account is admin, password is 123456

7) The virtual directory structure is referenced as follows:

<virtualhost *:80>    "d:/htdocs/grape/public/admin"    ServerName admin. Grape.  NET</virtualhost><virtualhost *:80>    "D:/htdocs/grape/public/api"     ServerName API. Grape. Net</VirtualHost>

II. directory Structure

Relying on the online open source framework initphp, slightly modified the initphp part of the source code, so that the structure more in line with my own project needs, and expanded several functions, such as full-text search configuration, paging and so on.

1)app: Place controller, attempt, interceptor, cache file, view compile file and specific configuration file, under app can have multiple project files, above admin and API belong to two projects

2)conf: Global configuration file, including database configuration, cache configuration, auto load configuration, etc., view initphp framework configuration .

3)initphp: Frame initphp library file, mostly original, there are several places to make adjustments. View all documents for the initphp framework .

4)Library: Including controller general files, data layer logic, data dictionary, form control writing, service layer logic, third-party code and simple test, here I put the library single out and app, initphp and Other level.

5)logs: Log file, you can print out the database query statements, you can also do some debugging information

6)public: Project entry file, global variable configuration, static resources (CSS, JS, etc.). As shown, the Admin folder has static resource files, CSS, JS, etc., and has its own index.php portal file, RPC file is the RPC call configuration in the initphp framework.

7)tool: Put MySQL Database sample code, easy API debugging tool, memcache operation tool

Iii. Configuration Files

1) Conf file

1. The global configuration is placed on the outside of the Conf file, and in each app under the project also has a conf file, which is to configure some of the configuration items required under this project.

2. The global configuration content is basically the same as in the initphp configuration , but I have a few more in the package.

is_xhprof: Profiling tool, Click View Tool Configuration .

Sphinx: Full-Text Search tool, Click View Tool Configuration .

autoload: Automatically loading files, loading some PHP files in the Library folder. The automatically loaded naming is regular, such as the first configuration below, which automatically loads the admincontroller.php file in the library/controller folder.

/* ******************************** Automatic load configuration **************************************** */ $InitPHP _conf Array (    ' path ' = = Lib_path. '/controller ',    array(' admin ', ' API ')); $InitPHP _conf Array (    ' path ' = = Lib_path. '/helper ',    array(' url ', ' dict/const ', ' Dict/enum '));

The auto-loaded logic code is written in the initphp initphp.php file:

Private Static function_autoload () {$config= Self::GetConfig (); $autoloads=$config[' AutoLoad ']; foreach($autoloads  as $key=$autoload) {            if(Empty($autoload[' Files ']) ||Empty($autoload[' Path ']))                Continue; $path=$autoload[' Path ']; foreach($autoload[' Files '] as $file) {                require_once $path. ‘/‘ .$file.Ucfirst($key).‘. Php; }        }        //whether to open the performance test        if($config[' Is_xhprof ']) {            require_onceLib_xhprof_path. "/xhprof_lib/utils/xhprof_lib.php"; require_onceLib_xhprof_path. "/xhprof_lib/utils/xhprof_runs.php"; }    }

2) Define global constants

1.defined.php

Files are located under public, this file will define directory constants, domain constants, API keys, configuration, etc., and introduce a global import file.

<?PHP/** * Constant definition * @author: Pwstrick*/Define(' Root_path ',dirname(dirname(__file__)));Define(' Lib_path ', Root_path. '/library ');Define(' Lib_third_path ', Lib_path. '/third ');//third-party class library catalogsDefine(' Lib_xhprof_path ', Lib_third_path. '/xhprof ');//Performance Testing ToolsDefine(' Script_path ', ' scripts ');//Development using scripts, deployment using optimizeDefine(' Upload_path ', Root_path. ') /upload ');//Upload PathDefine(' Upload_http ', ' http://upload.grape.net ');/** * API client Key*/Define(' Api_ios_key ', ' df_a98=d^&7$^%*9cnahj0uo!! LM11 ');Define(' Api_android_key ', ' ku98& ') dsf8% @kji89dfadJK -800i122 ');Define(' Api_unknow_key ', ' [email protected] (*kb66578-223q670933 ');/** * Configuration*/Define(' Weixin_appid ', ' xx ');//TODODefine(' Weixin_secret ', ' xx ');//TODODefine(' Weixin_token ', ' xx ');//TODODefine(' Weixin_notify_url ', ' http://xx ');//TODODefine(' Weixin_mchid ', ' xx ');//TODODefine(' Weixin_key ', ' xx ');//TODOHeader("content-type:text/html; Charset=utf-8 "); require_once(Root_path. '/initphp/initphp.php ');//Import configuration file-must be loaded inrequire_once(Root_path. '/conf/comm.conf.php ');//Public Configuration

2.index.php

The index folder is the entry file for each project, also under public, with specific configuration constants, referencing the defined.php file, and running the initphp development framework.

<? PHP require_once (dirname(dirname(__file__)). Directory_separator. ' defined.php '); Define (' app_name ', ' admin '); Define (' App_path ', Root_path. ') /app/'. app_name); require_once // App Configuration Initphp::init ();

GitHub Address:

Https://github.com/pwstrick/grape

Grape dynamic PHP structure (i)--directory structure and configuration file

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.