1. delete the cache in time after the cache template is modified. Otherwise, the modification will not take effect. 2. controller 2.1 assign values to variables note that & amp; #39; & amp; #39; is used for variables, rather than $ this-& gt; assign (& amp; #39; str & amp; #39;, & quot; H...
1. cache
You must delete the cache immediately after modifying the template. Otherwise, the modification will not take effect.
2. Controller
2.1 variable assignment
Note that ''is used for the variable, not $
$ This-> assign ('str', "Hello ThinkPHP! ");
Instead:
$ This-> assign ($ str, "Hello ThinkPHP! ");
2.2 Template path
$ This-> display ('default/Index/index'); do not add a suffix (.html or other); otherwise, the following error is reported.
The template does not exist [./Tpl/default/Index/index.html.html]
2.3 redirection
$ This-> redirect ("index ");
2.4 Model table
For example, $ Form = D ("Demo"); corresponds to the DB_PREFIX.demo table.
2.5 successes and errors
$ This-> success ("data written successfully"); if this is defined, you need to create a./Tpl/default/Public/success.html template.
$ This-> error ("data writing failed ");
Header ("Content-Type: text/html; charset = utf-8 ");
Exit ($ Form-> getError (). '[return]');
Main variables: {$ msgTitle} {$ message} {$ error} {$ waitSecond} {$ jumpUrl}
3. Template
3.1 Variable display
{$ Str}
3.2 form post
The form method must be specified as post. I have encountered an inexplicable error because this is not specified.
3.3 present label
.... Determine whether a variable is defined
4. common variables and constants
. Website root directory address
: Current project (entry file) address
_ URL __:
_ PUBLIC _: PUBLIC directory of the website, not the directory under the topic
_ CURRENT _: Template directory of the CURRENT module
APP_PATH: Current Project directory
LIB_PATH: Directory of the project class library
LANG_PATH: Project language file directory
COMMON_PATH: public file directory of the project
APP_PUBLIC_PATH: Project Public File Directory
APP_TMPL_PATH: Directory of the project template
TEMPLATE_PATH: current template path
WEB_PUBLIC_PATH: public directory of the website
More constants: http://www.thinkphp.cn/Manual/221
5. common functions
Highlight_file (LIB_PATH. 'action/IndexAction. class. php '); Highlight files. this is a function in PHP.
6. common code snippets
6.1 IndexAction. class. php
- Class IndexAction extends Action
- {
- Public function index ()
- {
- $ Form = D ("Form ");
- $ List = $ Form-> select ();
- $ This-> assign ('list', $ list );
- $ This-> display ('./Tpl/default/Index/index ');
- }
- Public function insert ()
- {
- $ Form = new Model ("Form ");
- If ($ Form-> Create ()){
- If (false! ==$ Form-> add ()){
- $ This-> success ("data written successfully ");
- } Else {
- $ This-> error ("data writing failed ");
- }
- } Else {
- Header ("Content-Type: text/html; charset = utf-8 ");
- Exit ($ Form-> getError (). '[return]');
- }
- }
- }
- ?>
6.2 FormModel. class. php
- Class FormModel extends Model {
- // Automatic verification settings
- Protected $ _ validate = array (
- Array ('title', 'require ', 'The title is required! ', 1 ),
- Array ('email ', 'Email', 'mailbox format error! ', 2 ),
- Array ('content', 'require ', 'content required '),
- Array ('title', '', 'title already exists ', 0, 'Unique', self: MODEL_INSERT ),
- );
- // Automatic filling settings
- Protected $ _ auto = array (
- Array ('status', '1', self: MODEL_INSERT ),
- Array ('create _ time', 'time', self: MODEL_INSERT, 'Function '),
- );
- }
- ?>