Program | Development Guide
Fleaphp is a highly flexible framework. Developers can use different settings to adjust the way fleaphp works. These settings are saved uniformly in a data source named application settings.
In fact, in addition to the fleaphp framework itself, applications can use application settings to save the various settings that the application needs to run.
The fleaphp application settings have a default profile, which is saved in FLEA/Config/Default_APP_INF.php
. The application can modify these settings in the entry file (for example index.php
) to adjust how the fleaphp works.
How do I use application settings?
When the fleaphp framework is initialized, the default application settings file ( Default_APP_INF.php
) is loaded. If your application wants to specify settings, there are several recommended practices:
To create a private settings file for an application
This method is recommended when you need to specify multiple application settings. It is very simple to define a file that resembles the following (assuming that the following content is saved to a file APP/Config/MY_APP_INF.php
).
<?phpreturn array( 'defaultController' => 'UserCenter', 'urlLowerChar' => false, 'dispatcher' => 'FLEA_Dispatcher_Auth', 'dbDSN' => array( 'driver' => 'mysql', 'host' => 'localhost', 'login' => 'root', 'password' =>空字符串, 'database' => 'test', ),);?>
Then index.php
run()
add a row before calling the function's code in the application's entry file register_app_inf('APP/Config/MY_APP_INF.php')
. For example:
<?phprequire('FLEA/FLEA.php');register_app_inf('APP/Config/MY_APP_INF.php');run();?>
Specify settings directly in the entry file
For a small number of settings, you can specify them directly in the entry file with the set_app_inf()
function. For example:
<?phprequire('FLEA/FLEA.php');set_app_inf('defaultController', 'UserCenter');run();?>
Whichever way you take it, it's important to specify the run()
application settings before you do so.
Default Application Settings
The default application settings provide settings that meet the needs of common application operations. The following categories list the names and detailed descriptions of these settings.
Core Configuration
- namespace The default namespace for the application, with the default value being an empty string
This setting affects the name definition of all the classes in the application. For example namespace
FOO
, when set to, all of the application's controller, model class names are prefixed FOO_
. Become like FOO_Controller_Default
, FOO_Model_News
wait.
To make your code easier to reuse in other applications, it's a good idea to set namespace to an empty string.
- controlleraccessor indicates the URL parameter name of the controller, and the default value is
controller
This setting specifies the controller name in the URL query parameter, with the name of the parameter. For example, when controlleraccessor is set to " ctl
", it must be used index.php?ctl=MyController
to specify the controller to invoke.
- Defaultcontroller Indicates the name of the default controller, and the default value is
Default
When a url
controller is not specified in the parameter to be invoked, the default controller is invoked according to the Defaultcontroller settings.
- actionaccessor and defaultaction, respectively,
action
and index
the default values areThe roles of these two settings are similar to those of ControlleraccessorandDefaultcontroller . is only used to specify the parameter name and default action name of the controller action.
- Urlmode Specifies the URL parsing and construction mode, and the default value is
URL_STANDARD
URL Analysis and construction mode, currently supports three kinds, respectively: URL_STANDARD
, URL_PATHINFO
and URL_REWRITE
.
URL_STANDARD
Pattern, the URL parameter takes a standard approach, such asindex.php?controller=MyController&action=MyAction&class_id=2&sort=1
For URL_PATHINFO
a URL_REWRITE
detailed description of the and, refer to using PathInfo and URL overrides.
- Urllowerchar Indicates whether the
url
controller name and action name contained in the parameter are coerced to lowercase characters, and the default value is false
For Windows systems, this setting does not matter. For Linux/unix systems, this setting is related to the naming of the Controller class definition file.
When Urllowerchar is in true
, the controller name is converted to lowercase characters, and the controller's class name is uppercase except for the first letter, and the others are all lower case. For example, the controller name is MyController
, the actual controller class name is Mycontroller
, the corresponding class definition file is Mycontroller.php
.
When Urllowerchar is false
, the controller name and the class name of the controller correspond exactly, for example the controller name is QuickBenchmark
, the actual controller class name is QuickBenchmark
, the corresponding class definition file is QuickBenchmark.php
.
- Controllerclassprefix indicates the controller class name prefix, and the default value is
Controller_
- actionmethodprefix and actionmethodsuffix indicate the prefix and suffix of the method name of the controller action, and the default values are the
action
and empty stringsYou can use prefixes and suffixes to distinguish the name of the controller action method from the other methods in the controller. You can also avoid inadvertently causing private methods within the controller to be accessed by the browser.
- Dispatcher indicates the URL scheduler to use for the application, and the default value is
FLEA_Dispatcher_Simple
The URL scheduler analyzes the URL parameters, determines which controller and controller action methods to invoke, and finally invokes the controller action method. The default FLEA_Dispatcher_Simple
is a simple scheduler that simply analyzes the URL parameters and completes the call work. More complex FLEA_Dispatcher_Auth
can be combined with FleaPHP
a self-contained RBAC
(role-based access Control) component to complete the access control function.
If the developer writes the scheduler himself, modifying this setting allows the application to use a scheduler that the developer has written for itself.
- Dispatcherfailedcallback indicates the handler to invoke after the scheduler fails, the default value is
null
If you want the application to handle a failure of the schedule, such as if the controller or controller method does not exist, you need to override this setting.
<?phpset_app_inf('dispatcherFailedCallback', 'appDispatcherFailedHandler');?>
- Internalcachedir indicates
cache
the cache directory used by the fleaphp internal and series functions, the default value is FLEA/_Cache/
directory
- autoload Indicates the file to be loaded automatically, default load
FLEA_Helper_Array.php
, FLEA_Helper_Html.php
and FLEA_Controller_Action.php
three filesThis setting must be an array in which each item in the array is the file to be loaded automatically.
- Sessionprovider indicates the
session
service provider to use, and the default value is null
If set to null
, represents a service that uses PHP itself session
.
- Autosessionstart Indicates whether support is automatically
session
enabled, and the default value is true
If this setting is true
, the function is automatically executed each time the fleaphp frame is initialized session_start()
.
- requestfilters Indicates which filters are used to filter HTTP requests, and the default value is an empty array
Similar to the autoload setting, this setting must be an array. However, each item in the array is the name of the filter class to be run. Filters are initialized and run in the order in which they appear in the array.
Each filter is actually a script and does not need to be implemented as a class. You can refer to FLEA/Filter/
the filter code in the directory to implement your own filter.
when fleaphp is initialized, it determines whether to run and filter automatically based on the PHP runtime environment settings and application settings FLEA_Filter_MagicQuotes
FLEA_Filter_Uri
. Therefore, developers should not call these two filters in the requestfilters settings .
Database-related
<?phpset_app_inf('dbDSN', array( 'driver' => 'mysql', 'host' => 'localhost', 'login' => 'username', 'password' => 'password', 'database' => 'test_db', ));?>
- Dbvalidationprovider Indicates the data validation service object to use for the table data entry, and the default value is
FLEA_Helper_Validation
View and stencil related
- View indicates the template engine to use, and PHP indicates that the PHP language itself is used as the template engine, and the default value is
PHP
Currently fleaphp provides a FLEA_View_Simple
template engine and a FLEA_View_Smarty
template engine. Which FLEA_View_Smarty
is actually a connector for connecting to the Smarty
template engine.
- viewconfig Specifies the configuration information to be used by the template engine, which defaults to
null
Different template engines may require different configurations, which can be viewConfig
specified with settings.
i18n
For more information about fleaphp support for i18n, refer to the relevant chapters of the development Guide.
- Responsecharset The encoding that indicates the use of the fleaphp output, and the default value is
gb2312
The fleaphp core itself does not assume that the content to be processed is encoded, nor does it automatically convert the input to the encoding specified by the output content. The responsecharset setting is only used as a reference, especially when Autoresponseheader is set to true
, fleaphp will automatically send out Content-Type: text/html; charset=xxxxx
the HTTP header information.
- Databasecharset indicates the encoding to be specified when fleaphp connects to the database, and the default value is
gb2312
Many of the more advanced databases, such as PostgreSQL, MySQL 4.1/5.x, Oracle, and so on, allow different encoded data to be stored in the database. So the developer should set the Databasecharset setting correctly so that the fleaphp can set the code correctly when connecting the database to avoid the garbled problem.
For older databases, such as MySQL 3.x/4.0, this setting has no meaning.
- Autoresponseheader Indicates whether
Content-Type: text/html; charset=xxxxx
HTTP header information is automatically exported, and the default value is true
When this is set to true
, fleaphp automatically outputs an HTTP header message at initialization to specify the encoding of the application output. Specifies what encoding is determined by the responsecharset setting.
For most servers, enabling this setting avoids the problem that browsers cannot correctly identify the output content encoding. However, in some server environments, enabling this setting causes problems such as the inability to output dynamic images.
- charsetconstant Indicates whether constants are automatically defined, and
RESPONSE_CHARSET
DATABASE_CHARSET
The default value is true
When this setting is set true
, fleaphp defines and constants, respectively, according to Responsecharset and databasecharset at initialization time RESPONSE_CHARSET
DATABASE_CHARSET
. Applications can simplify some development with these two constants.
- Multilangaugesupport Indicates whether multilanguage support is enabled, and the default value is
false
When this setting is set true
, the multilanguage Support service provider specified by Languagesupportprovider is automatically loaded.
- Languagesupportprovider Specifies a provider that provides multilanguage support, and the default value is
FLEA_Com_Language
FLEA_Com_Language
is a fleaphp support service provider with its own.
- Languagefilesdir indicates where the language file is saved, and the default value is
null
When you use multilanguage support, you must modify the setting to point to a directory that holds all language files.
Language files are stored in the directory structure of the language/dictionary name. PHP, for example, if languagefilesdir is set to /var/www/test/languages
, the actual file name of the language file may be: /var/www/test/languages/chinese-gb2312/user_interface.php
.
- defaultlanguage Indicates the default language, and the default value is
chinese-gb2312
If the language parameter is not specified when the language file is loaded, the dictionary file is downloaded from the language directory specified by defaultlanguage .
- Autoloadlanguage indicates the language dictionary to be loaded automatically, and the default value is
null
Autoloadlanguage can be an array, where each item is a dictionary name to be loaded. Or a string that separates multiple dictionary names with ",".
Flea_dispatcher_auth and RBAC components
- Dispatcherauthprovider Indicates the authentication service provider to be used by the scheduler, and the default value is
FLEA_Com_RBAC
FLEA_Com_RBAC
Provides a check()
way for the scheduler to check that the current initiating request has access to the specified controller and controller action method by calling the method. If a developer wants to write its own validation service provider, it must implement the check()
method. You can also use this setting to specify a validation service provider if you are using a scheduler that you have written yourself.
check()
The prototype of the method is:function check($roles, $ACT)
- defaultcontrolleractfile indicates the
RBAC
default ACT file to be used by the component, with the default value being an empty stringThis setting allows you to specify the ACT (Access control table) for multiple controllers without having to provide a single file for each controller .act.php
. Note that this setting specifies that the file must be a full path, or relative to the application entry ( index.php
) relative path.
- Autoquerydefaultactfile Indicates whether the
RBAC
component queries the act of the Controller from the default Act file when the Controller's Act file is not found, the default value is false
- controlleractloadwarning Indicates whether a warning message is displayed when the ACT of the controller is not found, and the default value is
true
- defaultcontrolleract indicates the default act to use when no act is supplied for the controller, and the default value is
null
- Dispatcherauthfailedcallback indicates the handler to invoke when the user does not have permission to access the controller or controller method, the default value is
null
- Rbacsessionkey instructs the RBAC component to save the user data in the session by using the key name, and the default value is
RBAC_USERDATA
If you are running multiple applications at the same time under a domain name, be sure to use your own unique key name for each application.
Log service and error handling
- logenabled Indicates whether the logging service is enabled, and the default value is
false
If this setting is true
, the log service provider specified by the logprovider setting is automatically loaded.
- Logprovider The program that indicates the log service, and the default value is
FLEA_Com_Log
- logfiledir indicates what directory to use to save the log file, and the default value is
null
It is a good idea to save the log in a directory that the browser cannot access.
- LogFileName Indicates what file name is used to save the log, and the default value is
access.log
- logfilemaxsize indicates that the log file is more than KB, automatically create a new logfile, in KB, not less than 512KB, with a default value of 4096
- logerrorlevel Indicates which level of errors to save to the log, the default value is ' Warning, error, exception '
- displayerrors Indicates whether an error message is displayed, and the default value is
true
- Friendlyerrorsmessage Indicates whether a friendly error message is displayed, and the default value is
true