FleaPHP single-entry document in Detail

Forum Posts: http://qeephp.com/bbs/thread-10922-1-1.html

Posts Reporter:

Posted record does not matter, just opening Ming Yi Bale. We can see that this thing can not help but ask, "Big Brother ah, do you this stuff in 2008, if not, posted in early 2007 said of the past, now posted, is it too late? What significance does ?. " Oh ......, night is bit late, or some sense. Although FleapHP's fans are now less and less, but because of its fewer people, we need to insist that only need to encourage each other. Confucius said, "Jen, I stick too!." Here, I have to say: "FleapHP, I stick too!" - FleapHP also I have been insisting on, you?

-------- X ------- x ------- x ------- x ------- x ----- x --- -> Beautiful separator <------ x ------- x ------ x ------ x ------ x -------- x ------- x -------- x -------

In FleaPHP application uses MVC pattern, the application of all functions through a single file to call. This single file to perform all the functions of the application procedure, known as single-entry application.

The file is usually placed in the main program directory. The code is as follows:

<?php
/**
 *  Import file
 *
 * @file:index.php
 * @author:hegz
 * @update:2009/10/27
 */

define('__ROOT__', dirname(__FILE__)); //  Defines the root directory of your Web site
define('DEPLOY_MODE', true); // Deployment mode enabled
//define('NO_LEGACY_FLEAPHP', true); // Compatible with the legacy FleaPHP  , Now effect  

//  Mount FleaPHP framework files
require(__ROOT__ . '/lib/FLEA/FLEA.php');

/**
 *  Mount configuration file
 */
FLEA::loadAppInf(__ROOT__ . DS . 'public/Config/COMMON_INF.php'); //  Custom environment profile
FLEA::loadAppInf(__ROOT__ . DS . 'public/Config/DSN.php'); //  The database link parameters configuration file
FLEA::loadAppInf(__ROOT__ . DS . 'APP/Config/APP_INF.php'); //  Custom application-configuration file  

/**
 *  Set the run directory
 */
FLEA::import(__ROOT__);
FLEA::import(__ROOT__ . DS . 'APP');
FLEA::import(__ROOT__ . DS . 'public');

//dump($GLOBALS['__FLEA_CORE__']['CLASS_PATH']); //  The debugger path
//exit;

//  To the MVC pattern running system
FLEA::runMVC();
?>

Note: the above code in the DS framework document for the FleaPHP defined path separator is a constant, Windows under the "\", Linux under the "/."

Code analysis

10th row:

define('__ROOT__', dirname(__FILE__));

Defined site root directory of the constant, the results may as shown below:

e: \ apmxe4 \ htdocs \ mmfs2010

Linux, may be:

/ Www/htdocs/mmfs2010

11th row:

define('DEPLOY_MODE', true);

Procedures deployed in real production environments when enabled, then the program will automatically call FleaPHP Frame FLEA / FLEA / Config / DEPLOY_MODE_CONFIG.php configuration file initialization program execution environment.
In the development environment, the need to display some error messages in detail, to facilitate debugging, you can be true to false, or you can directly block out the statement. As shown below:

define('DEPLOY_MODE', false);

Or directly to mask:

//define('DEPLOY_MODE', true);

At this point, the program will automatically call FleaPHP Frame FLEA / FLEA / Config / DEBUG_MODE_CONFIG.php profile initial program execution environment. Have time, we can compare the two files inside the configuration parameters of the similarities and differences.

15th row:

require(__ROOT__ . '/lib/FLEA/FLEA.php');

This well know, is loaded FleaPHP framework document FLEA.php, in the framework of the document loading process, the parameter values according to DEPLOY_MODE to load the default configuration file.

Article ~ 22 lines:

FLEA::loadAppInf(__ROOT__ . DS . 'public/Config/COMMON_INF.php');
FLEA::loadAppInf(__ROOT__ . DS . 'public/Config/DSN.php');
FLEA::loadAppInf(__ROOT__ . DS . 'APP/Config/APP_INF.php');

The three statements to load some custom configuration file, the program will run with the custom configuration file parameters override the default global configuration parameters.

Of which:

COMMON_INF.php files are shared environment configuration parameters, as follows:

<?php

return array(
    'controllerAccessor' => 'ctl',
    'defaultController'  => 'Default',
    'actionAccessor'     => 'act',
    'urlLowerChar'       => false,
    //'dispatcher'         => 'FLEA_Dispatcher_Auth',

    /**
     *  Scheduler scheduling failed  ( For example, the controller or the controller method does not exist  ) Later, to call the custom handler
     */
    'dispatcherFailedCallback'  => 'onDispatcherFailedCallback', //'dispatcher' = 'FLEA_Dispatcher_Simple' When you enable
    //'dispatcherAuthFailedCallback' => 'onAuthFailedCallback', //'dispatcher' = 'FLEA_Dispatcher_Auth' When you enable  

    /**
     *  Indicates when in the generated url  , Always use the application's entry, only the file name   URL_STANDARD  Mode
     *
     *  If this setting is false, the resulting   url  Similar  :
     *
     * http://www.example.com/?controller=xxx&action=yyy
     */
    'urlAlwaysUseBootstrap'     => false,

    /**
     *  Indicates when in the generated url  , Always use the full name of the controller and action name
     *
     *  If this setting is false, the default controller and action name does not appear in the   url  In
     */
    'urlAlwaysUseAccessor'      => false,

    'responseCharset'    => 'gb2312',
    'defaultLanguage'    => 'chinese-gb2312',
    'databaseCharset'    => 'gb2312',
    'RBACSessionKey'     => 'RBAC_MMFS2009',
    //'autoResponseHeader'        => false,
    'internalCacheDir'   => __ROOT__ . DS . '_cache',

    /**
     * WebControls  Extended controls save directory
     */
    'webControlsExtendsDir'     => __ROOT__ . DS . 'public/WebControls',

    /**
     *  Indicates whether to enable logging, set to  true When you enable
     */
    'logEnabled'         => false,

);

?>

DSN.php parameters for the database link definition file, as follows:

<?php
/**
 *  The database connection parameters
 */
return array(
    'dbDSN'     => array(
        'driver'        => 'mysql',
        'host'          => 'localhost',
        'login'         => 'mmfs2009',
        'password'      => ' ×××××××  ',
        'database'      => 'mmfs2009',
    )
);

?>

APP_INF.php custom foreground run parameter file, as follows:

<?php

return array(
    'dispatcher'       => 'FLEA_Dispatcher_Auth',

    /**
     *  Indicates whether the RBAC component you want to use the default   ACT  File  ( Use a single act file  )
     */
    'defaultControllerACTFile' => __ROOT__ . DS . 'APP/Controller/App.act.php',

    'view' => 'FLEA_View_Smarty',
    'viewConfig' => array(
        'smartyDir'         => __ROOT__ . DS . 'lib/Smarty',
        'template_dir'      => __ROOT__ . DS . 'APP/Templates',
        'compile_dir'       => __ROOT__ . DS . '_cache/1',
        'left_delimiter'    => '{{',
        'right_delimiter'   => '}}',
    ),
);
?>

Why do not these three configuration files into a configuration file as well? This is possible, but in some occasions to use less convenient, and easy modification. In general, the public after the configuration parameters configured little changes, but the link parameter in the deployment of the database parameters to the production environment, it is possible to modify the. Also, taking into account the foreground process and background process split into two directories, and if there is a back-entry documents, many parameters change, such as the path parameter, so before and after the Taiwan program requires a set of operating parameters have their own , then split the configuration file was very good.

27th ~ 29 lines:

FLEA::import(__ROOT__);
FLEA::import(__ROOT__ . DS . 'APP');
FLEA::import(__ROOT__ . DS . 'public');

The above statement is used to set the program to run directory. Implementation process, will route the data into the global array $ GLOBALS ['__FLEA_CORE__'] ['CLASS_PATH'] in the store, to facilitate subsequent use.

import () is defined in the framework document, which is a static method. The code is:

    /**
     *  Import the file search path
     *
     * FLEA::loadClass().FLEA::getSingleton()  In the search path Specifies the name of the class definition file  .
     *  Therefore you need to call the   FLEA::import()  The storage class definition file directories are added to the search path  .
     *  However, should not be the directory containing the class files are added directly to the search path  , But according to the naming of the class to determine which directory you want to add  .
     *
     *  For example, the class name is Table_Posts, while the actual file is   ./APP/Table/Posts.php.
     *  You should add directory is./APP, rather than   ./APP/Table .
     *
     * example:
     * <code>
     * FLEA::import(APP_DIR . '/LIBS');
     * </code>
     *
     * @param string $dir
     */
    function import($dir)
    {
        if (array_search($dir, $GLOBALS[G_FLEA_VAR]['CLASS_PATH'], true)) { return; }
        if (DIRECTORY_SEPARATOR == '/') {
            $dir = str_replace('\\', DIRECTORY_SEPARATOR, $dir);
        } else {
            $dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
        }
        $GLOBALS[G_FLEA_VAR]['CLASS_PATH'][] = $dir;
    }

Index.php file to remove the two backslashes, as shown below:

//dump($GLOBALS['__FLEA_CORE__']['CLASS_PATH']); //  The debugger path
//exit;

Remove the double slash:

dump($GLOBALS['__FLEA_CORE__']['CLASS_PATH']); //  The debugger path
exit;

Implementation of the program, results are as follows:

Array
(
[0] => e: \ apmxe4 \ htdocs \ mmfs2010 \ lib \ FLEA
[1] => e: \ apmxe4 \ htdocs \ mmfs2010
[2] => e: \ apmxe4 \ htdocs \ mmfs2010 \ APP
[3] => e: \ apmxe4 \ htdocs \ mmfs2010 \ public
)

Explain:

mmfs2010 - the main program directory,
lib \ FLEA - FleaPHP framework document storage directory
APP - foreground application directory, which contains a Config, Controller, Templates directory
public - the public file storage directory, which contains a Config, Model, Table, WebControls other subdirectory

35th row:

FLEA::runMVC();

Then the last entry in the file statement to MVC mode system. In the case of non-MVC mode system, the implementation of the

FLEA::init();

Command.

FLEA:: init () key to complete the following tasks:

Exception handling routines to install FleaPHP application settings under settings determine whether loading in magic_quotes log service check php.ini settings to on, and will be automatically escaped PHP escape after the withdrawal of data set according to the application to decide whether urlMode on the URL for processing according to the application running determine what set requestFilters input filter settings autoLoad decisions based application which automatically loads the file under the application settings sessionProvider and autoSessionStart decided to use which application session services according to the definition set responseCharset and requestCharset constants RESPONSE_CHARSET and DATABASE_CHARSET
According to the application to decide whether to set multiLangaugeSupport multi-language support included in the application settings autoResponseHeader according to whether the output HTTP HEADER information such automatic initialization procedure for the vast majority of applications are all necessary. So be sure to remember that require ('FLEA.php') after going to call FLEA:: init ().

FLEA:: runMVC () role:

If you want to use the MVC pattern FleaPHP. Then loaded FLEA.php, call FLEA:: runMVC () to start the MVC pattern.
In the MVC pattern starts, FleaPHP URL address according to the controller name and the controller contains the action name, the implementation of the controller developers to write code.

In fact, FLEA:: runMVC () calls inside the FLEA:: init () method.

分类:PHP 时间:2010-04-18 人气:245
分享到:
blog comments powered by Disqus

相关文章

  • ecshop part application to specify a different page template file 2010-07-09

    ecshop part application to specify a different page template file, which is a part of a style, the main application also in non-final part, the specific methods of operation are as follows: admin / templates / category_info.htm Which increase: <tr

  • / Usr / lib / libstdc + +. So.5: No such file or directory 2011-01-16

    In RedHat AS4 install Oracle10G, there comes the operating system and database package does not match the requirements of the error, Error message is as follows: / Usr / lib / libstdc + +. So.5: No such file or directory / Usr / lib / binutils *: No

  • JSON-lib application 2010-03-31

    Json essential package commons-httpclient-3.1.jar commons-lang-2.4.jar commons-logging-1.1.1.jar json-lib-2.2.3-jdk13.jar ezmorph-1.0.6.jar commons-collections-3.2.1.jar These packages can http://commons.apache.org/index.html http://json-lib.sourceforge.n

  • java application to read a complete sample configuration file 2008-12-01

    package com.jcms.cms.core; import java.io.BufferedInputStream; import java.io.InputStream; import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; / ** * * @ Author runningsnail * @ Date 2009-12-28 * * / public class Glo ...

  • Brother of the Linux private kitchens birds (Basics - 11.linux file and directory management) 2010-07-13

    1 • absolute path: the path from the root directory of a certain written 『/ write from』, for example: / usr / share / doc this directory. • Relative path: the path not by the wording of 『/ write from』, such as by the / usr / share / doc to go to / us

  • Brother of the Linux private kitchens birds - based learning articles 2 2011-09-14

    10 significance of the directory attribute r: represents the directory structure with read permissions on the list, so when r you have read permissions to the directory, you can use the ls command to list the contents of the directory w: writable permissi

  • FleaPHP single entry documents Xiangjie 2010-04-18

    Forum Posts: http://qeephp.com/bbs/thread-10922-1-1.html Posts Reporter: Posted record does not matter, just opening Ming Yi Bale. We can see that this thing can not help but ask, "Big Brother ah, do you this stuff in 2008, if not, posted in ear ...

  • strace command usage 2010-04-13

    Reprinted from: http://blog.chinaunix.net/u3/112657/showart_2207340.html strace command usage Call: strace [-dffhiqrtttTvxx] [-acolumn] [-eexpr] ... [-Ofile] [-ppid] ... [-sstrsize] [-uusername] [command [arg ...]] strace-c [-eexpr] ... [-Ooverhead] [-Sso

  • discuz File Description 2010-09-10

    File Color Description: Red: process core file, modify the type of file, be sure to pay attention to safety! Orange: do not use the file plug-ins almost probably be able to understand functions, and in fact I do not recommend to modify these files Green:

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.347 (s). 12 q(s)