Php+jquery Registration Module Improvements (iii): Updating to smarty3.1_php instances

Source: Internet
Author: User
Smarty3.1x (Latest version 3.1.19) has changed many features than smarty2.x. I have modified this module using Smarty3.1.18 (download address http://www.smarty.net/files/Smarty-3.1.18.zip) again, and the project files and directories look cleaner and more conditioned.

Copy the Libs folder from the Smarty package to the root of the module, and then create the init.inc.php in the root directory:

Copy the Code code as follows:
<?php
/**
file:init.inc.php instantiation and initialization files for Smarty objects
*/

/* *********************smarty Set *********************** */
Root path mode, for Smarty settings
Define ("ROOT", str_replace ("\ \", "/", DirName (__file__)). " /");

Require ROOT. ' libs/smarty.class.php ';
$smarty = new Smarty ();

Smarty3 Setting the default path
$smarty->settemplatedir (ROOT. ' templates/')
->setcompiledir (ROOT. ' templates_c/')
->setpluginsdir (ROOT. ' plugins/')
->setcachedir (ROOT. ' cache/')
->setconfigdir (ROOT. ' Configs ');

$smarty->caching = false;
$smarty->cache_lifetime = 60*60*24; Template cache validity time is 1 days
$smarty->left_delimiter = ' <{';
$smarty->right_delimiter = '}> ';

/***********************************************************/

Root directory URL method
$PHP _self=$_server[' php_self '];
$ROOT _url= ' http://' $_server[' Http_host '].substr ($PHP _self,0,strrpos ($PHP _self, '/') +1);
Define (Root_url, $ROOT _url);

Template Catalog URL method
Define ("Template_dir", $ROOT _url. ' Templates ');

Create the Templates,templates_c,plugins,cache,configs folder that appears in the initialization file.

The modified files are similar and very easy, and the modifications to the register.html and register.php files are listed here.

Register.html is the registered foreground page, the path is/templates/register.html

Copy the Code code as follows:




Registration page






<{* Import header.html*}>
<{include file= "header.html"}>







register.php:

Copy the Code code as follows:
<?php

Session_Start ();

Require_once ' init.inc.php ';

Set template directory for template page header reference CSS, JS, Images
$smarty->assign ("Template_dir", Template_dir);

$smarty->display (' register.html ');

At the same time, the build code plugin is expanded, the path is/plugins/function.showval.php

Copy the Code code as follows:
<?php

Generate Verification Code
function Smarty_function_showval ($params, $smarty) {

$num = "";
for ($i =0; $i <4; $i + +) {

$tmp = rand (1,15);
if ($tmp > 9) {
Switch ($tmp) {
Case (10):
$num. = ' a ';
Break
Case (11):
$num. = ' B ';
Break
Case (12):
$num. = ' C ';
Break
Case (13):
$num. = ' d ';
Break
Case (14):
$num. = ' E ';
Break
Case (15):
$num. = ' F ';
Break
}
} else {
$num. = $tmp;
}
}

$mdnum = MD5 ($num);
$_session[' num '] = $num;
$_session[' mdnum '] = $mdnum;

Written after the session
return $mdnum;
}

$_session[' num '] = Smarty_function_showval ($params, $smarty);
$_session[' mdnum ' = MD5 (Smarty_function_showval ($params, $smarty));

Note the name of the plugin:

The file name is placed under the plugins directory of the root directory, and the naming convention is function. The name of the function in PHP, the name of the functions in the file is the Smarty_function_ function ($params, $smarty), where the first argument is the associative array passed to the template. The second parameter is to receive the Smarty object that is automatically passed in, and the function has a return value.

For more code see: Https://github.com/dee0912/myGit

  • 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.