thinkphp Learn small notes (for beginners)

Source: Internet
Author: User
Tags apc file upload numeric value

Pre-background conditions

The project root directory is

http://localhost/site/

The new module is called home

We have an add function in the indexcontroller.php.

Public function Add () {
$this->show (' <style type= "text/css" >*{padding:0; margin:0;} div{padding:4px 48px;} body{background: #fff ; font-family: "Microsoft Ya Hei"; Color: #333; font-size:24px} h1{font-size:100px; font-weight:normal; margin-bottom:12px;} p{line-height:1.8em; font- size:36px}</style><div style= "padding:24px 48px;" > echo U (' Index/add ');
$this->display (' index ');

}


Access Path is

Http://localhost/site/home/Index/add

1. Question: How does the output URL be static

U (' Index/add ');
The default value is
/site/index.php/home/index/add.html

' Url_model ' => ' 1 ',//url mode
Return
/site/index.php/home/index/add.html

' Url_model ' => ' 2 ',//url mode
Return
/site/home/index/add.html

' Url_model ' => ' 3 ',//url mode
Return
/site/index.php?s=/home/index/add.html

2. Question: How to shorten the path

Total File index.php

Increase
Define (' Bind_module ', ' home ');

So the whole path was revised to

Http://localhost/site/Index/add

Url_model for 2 of the situation add return path revision change to

/site/index/add.html

3. Question: How to get the U method out of the path is lowercase
Necessary
Turn on debug mode suggest development phase open deployment phase Comment or set to False
Define (' App_debug ', false);

Required 2
config.php

' Url_case_insensitive ' => true,
Template tuning Path {: U (' Index/add ')}

4. Circular Template


Controller layer

$m = m (' Web ');
$result = $m->select ();
$this->assign (' list ', $result);
$this->display (' index ');
View Layer

<foreach name= "list" item= "V" >
{$key}| {$v. Name}
</foreach>


5. Template to find public documents
__public__

Output/site/public

6. Error, correct template hint config.php

' Tmpl_action_success ' => ' index:success ',//home/home/view/index/success.html

' Tmpl_action_error ' => ' index:success ',
Original Jump template file path

Thinkphp\tpl\

Supplemental configuration

Custom configuration: The default configuration for most common parameters in the Convention configuration is the first, because the custom configuration is the lowest priority, and if you do not need to make a special configuration, you can keep the default value, the custom configuration is located in thinkphp/conf/convention.php, the content excerpt as follows:


Copy Code


&lt;?php


/**


* Thinkphp Convention Profile


* Do not modify this file, if you want to overwrite the values of the Convention configuration, you can set the configuration items in the application configuration that do not conform to the custom


* Configuration name is arbitrary, the system will be converted to lower case


* All configuration parameters can be changed dynamically before they take effect


*/


Defined (' Think_path ') or exit ();


Return Array (


/* Application Settings * *


' App_use_namespace ' =&gt; true,//whether the Application class library uses namespaces


' App_sub_domain_deploy ' =&gt; false,//whether to open the child domain name deployment


' App_sub_domain_rules ' =&gt; Array (),//Sub-domain name deployment rules


' App_domain_suffix ' =&gt; ',//domain suffix if it is com.cn net.cn suffix must be set


' Action_suffix ' =&gt; ',//operation method suffix


' Multi_module ' =&gt; true,//whether multiple modules are allowed if false you must set the Default_module


' Module_deny_list ' =&gt; array (' Common ', ' Runtime '),


' Controller_level ' =&gt; 1,


' App_autoload_layer ' =&gt; ' Controller,model ',//automatically loaded application class library layer closed after app_use_namespace effective


' App_autoload_path ' =&gt; ',//automatically loaded path closed app_use_namespace effective

/* Cookie Settings * *
' Cookie_expire ' => 0,//COOKIE expiration
' Cookie_domain ' => ',//COOKIE valid domain name
' Cookie_path ' => '/',//COOKIE path
' Cookie_prefix ' => ',//COOKIE prefix avoids conflict

/* Default setting * *


' Default_m_layer ' =&gt; ' model ',//default models layer name


' Default_c_layer ' =&gt; ' Controller ',//default controller layer name


' Default_v_layer ' =&gt; ' view ',//default views layer name


' Default_lang ' =&gt; ' ZH-CN ',//default language


' Default_theme ' =&gt; ',//default template theme name


' Default_module ' =&gt; ' home ',//default module


' Default_controller ' =&gt; ' Index ',//Default controller name


' Default_action ' =&gt; ' index ',//default action name


' Default_charset ' =&gt; ' utf-8 ',//default output encoding


' Default_timezone ' =&gt; ' PRC ',//default time zone


' Default_ajax_return ' =&gt; ' json ',//default AJAX data return format, optional JSON XML ...


' Default_jsonp_handler ' =&gt; ' jsonpreturn ',//default processing method for JSONP format return


' Default_filter ' =&gt; ' htmlspecialchars ',//default parameter filtering method for I function ...

/* Database Settings * *


' Db_type ' =&gt; ',//database type


' Db_host ' =&gt; ',//server address


' Db_name ' =&gt; ',//database name


' Db_user ' =&gt; ',//username


' Db_pwd ' =&gt; ',//password


' Db_port ' =&gt; ',//Port


' Db_prefix ' =&gt; ',//database table prefix


' Db_fieldtype_check ' =&gt; false,//whether field type check


' Db_fields_cache ' =&gt; true,//enable field caching


' Db_charset ' =&gt; ' UTF8 ',//database encoding defaults to use UTF8


' Db_deploy_type ' =&gt; 0,//Database Deployment mode: 0 Centralized (single server), 1 distributed (Master-slave server)


' Db_rw_separate ' =&gt; false,//database read/write separate master-slave valid


' Db_master_num ' =&gt; 1,//read/write separated rear server number


' Db_slave_no ' =&gt; ',//specify from server serial number


' Db_sql_build_cache ' =&gt; false,//SQL create cache for database queries


' Db_sql_build_queue ' =&gt; ' file ',//SQL cache queue Caching method supports file XCache and APC


' Db_sql_build_length ' =&gt;,//SQL cache Queue Length


' Db_sql_log ' =&gt; false,//SQL execution logging


' Db_bind_param ' =&gt; false,//database write data automatic parameter binding

/* Data Cache Settings * *


' Data_cache_time ' =&gt; 0,//data cache expiration 0 means permanent cache


' Data_cache_compress ' =&gt; false,//data cache compression Cache


' Data_cache_check ' =&gt; false,//data cache checksum cache


' Data_cache_prefix ' =&gt; ',//cache prefix


' Data_cache_type ' =&gt; ' File ',//data cache type, support: file| db| apc| memcache| shmop| sqlite| xcache| apachenote| Eaccelerator


' Data_cache_path ' =&gt; temp_path,//cache path Settings (valid only for file-mode caching)


' Data_cache_subdir ' =&gt; false,//using a subdirectory cache (automatically create subdirectories based on the hash of cached identities)


' Data_path_level ' =&gt; 1,//subdirectory cache level

   /* ERROR settings */
    ' error_message '           =>  ' page error! Please try again later ~ ',//error display information, non-debug mode valid
    ' error_page '              =>  ',   //Error oriented page
    ' show_error_msg '          =>  false,   //Display error message
    ' Trace_max_ Record '       =>  100,   //maximum number of error messages per level

   /* Log settings */
    ' Log_record '              =>  false,  //default log not logged
    ' Log_type '                =>  ' files ',//logging type defaults to file mode
     ' log_level '              =>  ' Emerg,alert,crit,err ',//log level allowed logging
    ' log_file_size '           =>  2097152,   //log file size limit
    ' log_exception_record '   = >  false,   //Whether the exception information log is logged

/* Session Settings * *
' Session_auto_start ' => true,//whether session is automatically opened
' Session_options ' => Array (),//session configuration array supports parameters such as type name ID path expire domain
' Session_type ' => ',//session hander type default without setting unless extended session hander driver
' Session_prefix ' => ',//session prefix
' var_session_id ' => ' session_id ',//sessionid's submission variable

/* Template engine settings * *


' Tmpl_content_type ' =&gt; ' text/html ',//default template output type


' Tmpl_action_error ' =&gt; think_path. ' Tpl/dispatch_jump.tpl ',///Default error jump corresponding template file


' Tmpl_action_success ' =&gt; think_path. ' Tpl/dispatch_jump.tpl ',///default successful jump to corresponding template file


' Tmpl_exception_file ' =&gt; think_path. ' Tpl/think_exception.tpl ',//template file for the exception page


' Tmpl_detect_theme ' =&gt; false,//Automatically detect template theme


' Tmpl_template_suffix ' =&gt; '. html ',//default template file suffix


' Tmpl_file_depr ' =&gt; '/', the separator between the template file Controller_name and Action_name


Layout settings


' Tmpl_engine_type ' =&gt; ',//default template engine The following settings are valid only for use of the just-in-a-way template engine


' Tmpl_cachfile_suffix ' =&gt; '. php ',//default template cache suffix


' Tmpl_deny_func_list ' =&gt; ' echo,exit ',//template engine disable function


' tmpl_deny_php ' =&gt; false,///The default template engine disables PHP native code


' Tmpl_l_delim ' =&gt; ' {',//template engine normal label start tag


' Tmpl_r_delim ' =&gt; '} ',//template engine normal tag end tag


' Tmpl_var_identify ' =&gt; ' array ',//template variable identification. Leave blank automatically to determine that the parameter is ' obj ' to represent the object


' Tmpl_strip_space ' =&gt; true,//whether to remove HTML spaces and line wrapping in the template file


' tmpl_cache_on ' =&gt; true,//whether to open the template compilation cache, set to False to recompile each time


' Tmpl_cache_prefix ' =&gt; ',//template cache prefix identification, can dynamically change


' Tmpl_cache_time ' =&gt; 0,//template cache validity 0 is permanent, (in numeric value, in seconds)


' Tmpl_layout_item ' =&gt; ' {__content__} ',//Layout template content Replacement identification


' layout_on ' =&gt; false,//whether layout is enabled


' Layout_name ' =&gt; ' LAYOUT ',//Current layout name defaults to LAYOUT

I-am template engine tag Library related settings


' Taglib_begin ' =&gt; ' &lt; ',//tag library tag start tag


' Taglib_end ' =&gt; ' &gt; ',//tag library tag end tag


' Taglib_load ' =&gt; true,//whether to use a tag library other than the built-in tag library, default Auto Detect


' taglib_build_in ' =&gt; ' cx ',//built-in tag library name (label use does not need to specify tag library name), comma-separated attention to parse order


' Taglib_pre_load ' =&gt; ',//need additional load tag library (must specify tag library name), multiple comma separated





/* URL Settings * *


' Url_case_insensitive ' =&gt; true,//default False to indicate that the URL is case-sensitive true indicates case-insensitive


' Url_model ' =&gt; 1,//URL access mode, optional parameters 0, 1, 2, 3, representing the following four modes:


0 (normal mode); 1 (pathinfo mode); 2 (REWRITE mode); 3 (Compatibility mode) defaults to PathInfo mode


' Url_pathinfo_depr ' =&gt; '/'////////////PathInfo mode, split symbol between parameters


' Url_pathinfo_fetch ' =&gt; ' orig_path_info,redirect_path_info,redirect_url ',//list of server substitution variables for compatible judgment path_info parameters


' Url_request_uri ' =&gt; ' Request_uri ',//Get the current page address of the system variable defaults to Request_uri


' Url_html_suffix ' =&gt; ' HTML ',//URL pseudo static suffix settings


' Url_deny_suffix ' =&gt; ' ico|png|gif|jpg ',//URL forbidden to access suffix settings


' Url_params_bind ' =&gt; true,//URL variable bound to action method argument


' Url_params_bind_type ' =&gt; 0,//URL variable binding type 0 by variable name binding 1 binding in variable order


' Url_404_redirect ' =&gt; ',//404 Jump page Deployment mode effective


' url_router_on ' =&gt; false,//whether URL routing is turned on


' Url_route_rules ' =&gt; Array (),//default routing rules for modules


' Url_map_rules ' =&gt; Array (),//URL mapping definition Rule

/* System Variable Name set * *


' Var_module ' =&gt; ' m ',//default module get variable


' Var_controller ' =&gt; ' C ',//default controller get variable


' Var_action ' =&gt; ' a ',//default action get variable


' Var_ajax_submit ' =&gt; ' ajax ',//default AJAX submission Variable


' Var_jsonp_handler ' =&gt; ' callback ',


' Var_pathinfo ' =&gt; ' s ',//compatibility mode PathInfo Get variables for example? S=/MODULE/ACTION/ID/1 the following parameters depend on the URL_PATHINFO_DEPR


' Var_template ' =&gt; ' t ',//default template toggle Variable

' Http_cache_control ' => ' private ',//Web cache control
' Check_app_dir ' => true,//whether to check whether the application directory is created
' File_upload_type ' => ' local ',//File upload mode
' Data_crypt_type ' => ',//Data encryption method

);
Copy Code

Application configuration: A public configuration file loaded before all modules are invoked, located in application/common/conf/ config.php, Note If you modify the name of the public module, the location of the public profile will be changed accordingly, there is nothing in the application configuration, you need to add it yourself, as follows:
<?php
Return Array (
' Configuration item ' => ' config value '
);
Mode configuration: If you use an application mode other than normal application mode, you can add the configuration file separately for the application mode, where the file is stored and the naming rules are as follows: Application/common/conf/config_ Application Mode name. PHP, note that mode configuration is only loaded in run mode
Debug Configuration: If Debug mode is turned on, the Debug configuration file for the framework and the Debug configuration file are automatically loaded, where they are located in the thinkphp/conf/debug.php,application/common/conf/debug.php
State configuration: Each application can set its own state under different circumstances, also known as the application scenario, if we want to differentiate the development environment and test environment, define define (' App_status ', ' development ') in the entry file; Then the corresponding configuration file application/common/conf/development.php is loaded, if modified to define (' app_status ', ' test ') in the entry file; Then the corresponding configuration file will be loaded application/common/conf/test.php
Module configuration: Each module will load its own configuration file, and the module in the same directory, such as: application/the current module name/conf/ config.php, if you use an application mode other than normal mode, you can also define the configuration file for the application mode separately, name and storage directory such as: application/Current module name/conf/config_ Application Mode name. PHP, note that this is only loaded in run mode, and the module configuration file is optional.

If you apply a larger profile, you want to split into separate profiles or load additional configuration files to use extended configuration and dynamic configuration.
2. Read configuration

Thinkphp uses the C method to read configuration nodes, which is the meaning of config, note that the parameters of the configuration item are not case-sensitive, C (' Url_model ') and C (' Url_model ') get the same result, but it is recommended that the case be case-sensitive. The configuration parameter name cannot use '. ' because it is used to read two-dimensional parameters, or null if there is no configuration. The method for reading two-dimensional parameter values is as follows: C (' User_config. User_type ');

3. Dynamic configuration

You can write configuration parameters in advance, or you can set them dynamically in a method, using the C method, for example: C (' parameter name ', ' new parameter value '); Dynamic configuration is valid only for the current request and not for other requests. Note that the dynamic configuration method is the same as the method of reading the configuration, except for one more parameter.

4. Extended Configuration

The extended configuration can automatically load additional custom profiles, as well as the format of the configuration format and the project configuration, by setting the extended configuration as follows:

Load Extended configuration file
' Load_ext_config ' => ' user,db ',

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.