
1.Home是前台项目文件夹,Admin是后台项目文件夹,Public存储图片。
2.在根目录下,编辑index.php前台入口文件和admin.php后台入口文件,代码如下
//index.php
<?php
define('APP_NAME','19');
define('APP_PATH','./Home/');
require("./ThinkPHP/ThinkPHP.php");
?>
//admin.php
<?php
define('APP_NAME','Admin');
define('APP_PATH','./Admin/');
require("./ThinkPHP/ThinkPHP.php");
?>
3.运行前后台文件让其自动生成项目目录后,编辑Admin\Conf目录下的config.php文件,代码如下<?php
return array(
'APP_DEBUG' => false,
'DB_TYPE' => 'mysql',
'DB_HOST' => 'localhost',
'DB_NAME' => 'php',
'DB_USER' => 'root',
'DB_PWD' => '',
'DB_PORT' => '3306',
'DB_PREFIX' => 'think_',
);
?>
4.编写后台项目的控制器(Admin\Lib\Action目录下)。创建Index模块,定义index()方法读取数据表中的数据代码如下<?php
header("Content-type:text/html;charset=utf-8");
class IndexAction extends Action {
public function index(){
$db = new Model('message');
$select = $db->select();
$this->assign('select',$select);
$this->display();
}
}
?>
5.然后创建User模块,定义insert()方法,将表单中提交的数据添加到指定的数据表中,成功后重定向到后台主页,代码如下<?php
header("Content-type:text/html;charset=utf-8");
class UserAction extends Action {
public function insert(){
$ins = new Model('message');
$ins->Create();
$result = $db->add();
$this->redirect('Index/index','',5,'页面跳转中');
}
}
?>
6.在Admin\Tpl\目录下创建Index文件夹,编辑index操作的模版文件index.html,代码如下 <table>
<volist name='select' id='user'>
<tr>
<td bgcolor="#FFFFFF"> {$user.username}</td>
<td bgcolor="#FFFFFF"> {$user.address}</td>
</tr>
</volist>
</table>
7.创建User模块文件夹,编辑insert操作的模版文件index.html,创建添加用户信息的表单。代码如下<form method="post" action="__URL__/insert">
<table width="265" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>用户名:</td>
<td><input name="username" type="text" size="15" /></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password" size="15" /></td>
</tr>
<tr>
<td>地址:</td>
<td><input type="text" name="address" size="20" /></td>
</tr>
</table>
<input type="image" name="imageField" id="imageField" src="./Public/images/66_05.gif" />
</form>
8.编辑前台项目(Home\conf)的数据库配置文件。代码跟第3步的一样。9.创建前台项目控制器Index(Home\Lib\Action),定义index()方法查询数据,并且将结果赋给模版变量;定义insert()方法,通过R快捷方式调用Admin项目UserAction控制器的insert操作方法完成数据的添加操作,代码如下
<?php
class IndexAction extends Action {
public function index(){
$db = new Model('message');
$select = $db->select();
$this->assign('select',$select);
$this->display();
}
public function insert() {
$ins = R("User","insert","Admin");
$ins->Create();
$result = $ins->add();
}
}
10.在Home\Tpl\目录下,创建Index模块文件夹,编辑index操作的模块文件index.html,代码如下<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户管理</title>
<style type="text/css">
<!--
body{
margin:auto;
}
.title {
font-weight: bold;
font-size: 13px;
}
.content {
font-size: 12px;
}
#td {
text-align: right;
}
-->
</style>
</head>
<body>
<form method="post" action="__URL__/insert" >
<table id="__01" width="404" height="205" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5">
<img src="./Public/images/66_01.gif" width="404" height="53" alt=""></td>
</tr>
<tr>
<td rowspan="3">
<img src="./Public/images/66_02.gif" width="132" height="151" alt=""></td>
<td>
<img src="./Public/images/66_03.gif" width="1" height="102" alt=""></td>
<td colspan="3" width="271" height="102" bgcolor="#FaFaFa">
<table width="265" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="title" id="td">用户名:</td>
<td><input name="username" type="text" size="15" /></td>
</tr>
<tr>
<td class="title" id="td">密码:</td>
<td><input name="password" type="password" size="15" /></td>
</tr>
<tr>
<td class="title" id="td">地址:</td>
<td><input name="address" type="text" size="20" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><input type="image" alt="Sumbit" name="imageField" id="imageField" src="./Public/images/66_05.gif" /></td>
<td>
<input type="image" name="reset" alt="reset" id="reset" src="./Public/images/66_06.gif" style="width:107; height:36" onclick="form.reset();return false;" />
</td>
<td>
<img src="./Public/images/66_07.gif" width="60" height="36" alt=""></td>
</tr>
<tr>
<td>
<img src="./Public/images/66_08.gif" width="1" height="13" alt=""></td>
<td colspan="3">
<img src="./Public/images/66_09.jpg" width="271" height="13" alt=""></td>
</tr>
<tr>
<td>
<img src="./Public/images/分隔符.gif" width="132" height="1" alt=""></td>
<td>
<img src="./Public/images/分隔符.gif" width="1" height="1" alt=""></td>
<td>
<img src="./Public/images/分隔符.gif" width="104" height="1" alt=""></td>
<td>
<img src="./Public/images/分隔符.gif" width="107" height="1" alt=""></td>
<td>
<img src="./Public/images/分隔符.gif" width="60" height="1" alt=""></td>
</tr>
</table>
</form>
<table width="405" border="1" cellpadding="1" cellspacing="1" bgcolor="#99CC33" bordercolor="#FFFFFF">
<tr>
<td bgcolor="#FFFFFF" colspan="3"> </td>
</tr>
<tr class="title">
<td bgcolor="#FFFFFF" width="120">用户名</td>
<td bgcolor="#FFFFFF" width="120">密码</td>
<td bgcolor="#FFFFFF" width="223">地址</td>
</tr>
<volist name='select' id='user' >
<tr class="content">
<td bgcolor="#FFFFFF"> {$user.username}</td>
<td bgcolor="#FFFFFF"> {$user.password}</td>
<td bgcolor="#FFFFFF"> {$user.address}</td>
</tr>
</volist>
</table>
</body>
</html>
最后运行效果:
但是点注册却变成

所以请问一下,这过程有什么错误吗?请大神们帮忙,十分感谢!!!
最佳答案
