sample
---- A
-------- .root.php
-------- user.php
-------- userLogin.php
-------- userLogout.php
-------- userRegister.php
---- css -- 样式表
---- fonts -- 字体
---- images -- 图片
---- js -- 脚本
---- jtongfu
---- WEB-APP -- 系统目录(非用户访问目录)
--------- classes -- 用户自定义模块
-------------- sample_system.inc.php -- 系统对象
-------------- keywords.inc.php -- 字典库
--------- smarty -- 模板目录
-------------- tpls -- 模板源目录
------------------ header.htm
------------------ footer.htm
------------------ A
---------------------- user.html
---------------------- userLogin.html
---------------------- userRegister.html
-------------- coms -- 模板编译目录
--------- config.inc.php -- 环境文件
--------- web.inc.php -- 配置文件
---- index.php -- 索引文件
旧版本的框架使用的是 inc 作为文件扩展名,新版本的框架已经换成了 inc.php 作为文件扩展名了!
CREATE TABLE `user` ( `uId` int NOT NULL AUTO_INCREMENT , `uName` varchar(45) NULL , `uPwd` char(32) NULL , `crtDT` datetime NULL , `logDT` datetime NULL , `logTimes` int NULL , PRIMARY KEY (`uId`), UNIQUE INDEX `u_name` (`uName`) );
WEB-APP/smarty/tpls/header.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <% $__header %> </head> <body> <div id="wrapper"> <div id="page-wrapper"> <div class="wrapper wrapper-content animated fadeInRight">
WEB-APP/smarty/tpls/footer.htm
</div> </div> </div> </body> </html>
GET /A/user.php
A/user.php
require('.root.php'); require(WEBAPP_ROOT); linking('html.form_action3'); using('user_action'); // 用户列表对象 class user_std_action extends table_action_ctl { public function __construct($name){ parent::__construct($name); $this->add_usr_action("mod","修改"); $this->add_usr_action("del","删除"); } } class user_table extends table_action3 { public $loginUser; public $actionObj; protected function filter_row(&$row){ $this->actionObj->set_action_link($row,"mod",$row['pmId']); // pmId - primary key id } protected function get_sql(&$sql){ $sql = "select uId, uName, crtDT, logDT, logTimes from user"; } protected function get_table_show_argv(table_action3_argv &$argv){ $argv->actions = $this->actionObj->get_actions(); } } class user_action extends table_action_ctl { public function __construct($name){ parent::__construct($name); } } class user_page extends form_action3{ public $loginUser; public $actionObj; protected function process(){ // 初始化用户列表 $tablePage = new user_table("user", $this->tableConfig, $this->pageObj, $this->smartyObj, $this->dbObj, array('ID', '用户名', '注册时间', '登录时间', '登录次数')); $tablePage->loginUser = $this->loginUser; $tablePage->actionObj = new user_action("user"); $tablePage->make_table(); // 登录用户信息 $myUserActObj = new tf_user_action($this->dbObj); $uid = $myUserActObj->testLoginCookie($this->pageObj); $this->smartyObj->cfg("loginUserInfo", ($uid > 0) ? $myUserActObj->get_row($uid) : array()); } } class user extends sample_system{ private $actionPage; public $actionObj; public function __construct($args){ parent::__construct($args); $this->smartyFile = "A/user"; $this->regPublicKey = "user"; $this->page->title = "Title of 'user'"; // $this->tableConfig = new table_maker_config("user"); $this->actionObj = new user_action("user"); $this->actionPage = new user_page($this->tableConfig, $this->page, $this->smarty, $this->dbo, $this->actionObj->get_keys(), $this->actionObj->defaultAction); $this->actionPage->set_no_methods($this->actionObj->get_no_methods()); $this->actionPage->loginUser = $this->loginUser; $this->actionPage->actionObj = $this->actionObj; } public static function main($args){ $myPg = new user($args); $myPg->actionPage->action_process(); $myPg->done_smarty(); } } user::main(array( 'mysql' ));
WEB-APP/smarty/tpls/A/user.html
<% include file="header.htm" %> <div > <% if $loginUserInfo.uId > 0 %> <b><% $loginUserInfo.uName %></b> <a href="<% $__page->docRoot %>A/userLogout.php">注销登录</a> <% else %> <a href="<% $__page->docRoot %>A/userLogin.php">登录</a> <a href="<% $__page->docRoot %>A/userRegister.php">注册</a> <% /if %> </div> <h1 style="text-align:center;">用户列表</h1> <% $stdTable_user %> <% include file="footer.htm" %>
GET /A/userRegister.php
A/userRegister.php
require('.root.php'); require(WEBAPP_ROOT); linking('html.form_action3'); using('user_action'); // 注册表单对象 class register_act extends form_action_item3{ protected function create_validator(){ $this->validator = new form_validator_action3(); $this->validator->add_rule("user", "r1(min[4]max[20])", array("最少4个字符", "最长20个字符"), "请填写用户名"); $this->validator->add_rule("pwd", "r1(min[4]max[20])", array("最少4个字符", "最长20个字符"), "请填写密码"); $this->validator->add_rule("vpwd", "r1(sas[pwd])", array("两次输入的密码不一致"), "请填写确认密码"); } protected function create_form(){ $this->form = new form_maker_action3($this->tableConfig, $this->pageObj, "form_act"); $this->form->set_target(); $this->form->add_textfield("user"); $this->form->add_password("pwd"); $this->form->add_password("vpwd"); $this->form->add_button("btnSubmit",1,"提交"); } protected function get_arg(&$arg){ $arg['class'] = "ctongfuTableForm"; $arg['labels'] = array('用户名', '密码', '确认密码'); } protected function form_error($err){ $this->pageObj->parentAlertBack(implode("\n", $err)); } protected function process($arr, &$err){ $myUserActObj = new tf_user_action($this->dbObj); // 用户名检查 $dup = $this->dbObj->sr("select * from user where uName = @str", $arr['user']); if($dup){ $err['user'] = "用户名已经存在"; return; } // 用户注册 $iSql = $this->dbObj->ib("user", array('uName'=>$arr['user'], 'uPwd'=>md5($arr['pwd']))); $this->dbObj->se($iSql); $newUserId = $this->dbObj->last_insert_id(); if(!($newUserId > 0)){ $err['user'] = "注册失败"; return; } // 写入COOKIE $exist = $this->dbObj->sr("select * from user where uName = @str", $arr['user']); $myUserActObj->setLoginCookie($this->pageObj, $exist); // 返回列表 $this->pageObj->parentGotoUrl($this->pageObj->U("A/user.php")); } } class userRegister_action extends table_action_ctl { public function __construct($name){ parent::__construct($name); } } class userRegister_page extends form_action3{ public $loginUser; public $actionObj; protected function process(){ // 初始化注册表单 $toolPage = new register_act("register", $this->smartyObj, $this->dbObj, array(), "事件", $this->pageObj); $toolPage->tableConfig = $this->tableConfig; $toolPage->action_process(); } } class userRegister extends sample_system{ private $actionPage; public $actionObj; public function __construct($args){ parent::__construct($args); $this->smartyFile = "A/userRegister"; $this->regPublicKey = "userRegister"; $this->page->title = "Title of 'userRegister'"; // $this->tableConfig = new table_maker_config("userRegister"); $this->actionObj = new userRegister_action("userRegister"); $this->actionPage = new userRegister_page($this->tableConfig, $this->page, $this->smarty, $this->dbo, $this->actionObj->get_keys(), $this->actionObj->defaultAction); $this->actionPage->set_no_methods($this->actionObj->get_no_methods()); $this->actionPage->loginUser = $this->loginUser; $this->actionPage->actionObj = $this->actionObj; } public static function main($args){ $myPg = new userRegister($args); $myPg->actionPage->action_process(); $myPg->done_smarty(); } } userRegister::main(array( 'mysql' ));
WEB-APP/smarty/tpls/A/userRegister.html
<% include file="header.htm" %> <h1 style="text-align:center;">用户注册</h1> <% $actFormS_register %> <% $actFormJS_register %> <% include file="footer.htm" %>
GET /A/userLogin.php
A/userLogin.php
require('.root.php'); require(WEBAPP_ROOT); linking('html.form_action3'); using('user_action'); // 登录表单对象 class login_act extends form_action_item3{ protected function create_validator(){ $this->validator = new form_validator_action3(); $this->validator->add_rule("user", "r1(min[4]max[20])", array("最少4个字符", "最长20个字符"), "请填写用户名"); $this->validator->add_rule("pwd", "r1(min[4]max[20])", array("最少4个字符", "最长20个字符"), "请填写密码"); } protected function create_form(){ $this->form = new form_maker_action3($this->tableConfig, $this->pageObj, "form_act"); $this->form->set_target(); $this->form->add_textfield("user"); $this->form->add_password("pwd"); $this->form->add_button("btnSubmit",1,"提交"); } protected function get_arg(&$arg){ $arg['class'] = "ctongfuTableForm"; $arg['labels'] = array('用户名', '密码'); } protected function form_error($err){ $this->pageObj->parentAlertBack(implode("\n", $err)); } protected function process($arr, &$err){ $myUserActObj = new tf_user_action($this->dbObj); // 用户名检查 $exist = $this->dbObj->sr("select * from user where uName = @str", $arr['user']); if($exist == null){ $err['user'] = "用户名不存在"; return; } else if($exist['uPwd'] != md5($arr['pwd'])){ $err['user'] = "密码错误"; return; } // 写入COOKIE $myUserActObj->setLoginCookie($this->pageObj, $exist); // 返回列表 $this->pageObj->parentGotoUrl($this->pageObj->U("A/user.php")); } } class userLogin_action extends table_action_ctl { public function __construct($name){ parent::__construct($name); } } class userLogin_page extends form_action3{ public $loginUser; public $actionObj; protected function process(){ // 初始化登录表单 $toolPage = new login_act("login", $this->smartyObj, $this->dbObj, array(), "事件", $this->pageObj); $toolPage->tableConfig = $this->tableConfig; $toolPage->action_process(); } } class userLogin extends sample_system{ private $actionPage; public $actionObj; public function __construct($args){ parent::__construct($args); $this->smartyFile = "A/userLogin"; $this->regPublicKey = "userLogin"; $this->page->title = "Title of 'userLogin'"; // $this->tableConfig = new table_maker_config("userLogin"); $this->actionObj = new userLogin_action("userLogin"); $this->actionPage = new userLogin_page($this->tableConfig, $this->page, $this->smarty, $this->dbo, $this->actionObj->get_keys(), $this->actionObj->defaultAction); $this->actionPage->set_no_methods($this->actionObj->get_no_methods()); $this->actionPage->loginUser = $this->loginUser; $this->actionPage->actionObj = $this->actionObj; } public static function main($args){ $myPg = new userLogin($args); $myPg->actionPage->action_process(); $myPg->done_smarty(); } } userLogin::main(array( 'mysql' ));
WEB-APP/smarty/tpls/A/userLogin.html
<% include file="header.htm" %> <h1 style="text-align:center;">用户登录</h1> <% $actFormS_login %> <% $actFormJS_login %> <% include file="footer.htm" %>
GET /A/userLogout.php
A/userLogout.php
require('.root.php'); require(WEBAPP_ROOT); linking('html.form_action3'); using('user_action'); class userLogout_action extends table_action_ctl { public function __construct($name){ parent::__construct($name); } } class userLogout_page extends form_action3{ public $loginUser; public $actionObj; protected function process(){ // 注销登录 $myUserActObj = new tf_user_action($this->dbObj); $myUserActObj->clearLoginCookie($this->pageObj); // 返回列表 $this->pageObj->gotoUrl($this->pageObj->U("A/user.php")); } } class userLogout extends sample_system{ private $actionPage; public $actionObj; public function __construct($args){ parent::__construct($args); $this->smartyFile = "A/userLogout"; $this->regPublicKey = "userLogout"; $this->page->title = "Title of 'userLogout'"; // $this->tableConfig = new table_maker_config("userLogout"); $this->actionObj = new userLogout_action("userLogout"); $this->actionPage = new userLogout_page($this->tableConfig, $this->page, $this->smarty, $this->dbo, $this->actionObj->get_keys(), $this->actionObj->defaultAction); $this->actionPage->set_no_methods($this->actionObj->get_no_methods()); $this->actionPage->loginUser = $this->loginUser; $this->actionPage->actionObj = $this->actionObj; } public static function main($args){ $myPg = new userLogout($args); $myPg->actionPage->action_process(); $myPg->done_smarty(); } } userLogout::main(array( 'mysql' ));
无
无
以上就通过TFAPI框架实现了一个用户模块的基本功能的实例,希望对大家有帮助~~
这个版本的开发需要 1.0.0 以上的版本的TFAPI框架支持
最早的版本也是基于OOP开发的,完全的面向对象编程。只不过数据操作是直接通过 $this->dbObj 在视图完成的