过了前面的坎儿,现在搞起来顺利多了。
1、新建模板文件,utf8格式,D:\wamp\www\MyWeb\Application\Home\View\Edit\edit.html
<html>
<head>
<title>Edit Data</title>
</head>
<body>
<FORM method="post" action="__URL__/update">
标题:<INPUT type="text" name="title" value="{$vo.title}"><br/>
内容:<TEXTAREA name="content" rows="5" cols="45">{$vo.content}</TEXTAREA><br/>
<INPUT type="hidden" name="id" value="{$vo.id}">
<INPUT type="submit" value="提交">
</FORM>
</body>
</html>
2、新建控制器,D:\wamp\www\MyWeb\Application\Home\Controller\EditController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class EditController extends Controller {
public function edit($id=0){
$Form = M('Form');
$this->vo = $Form->find($id);
$this->display();
}
public function update(){
$Form = D('Form');
if($Form->create()) {
$result = $Form->save();
if($result) {
$this->success('操作成功!');
}else{
$this->error('写入错误!');
}
}else{
$this->error($Form->getError());
}
}
}
3、浏览:http://localhost/MyWeb/index.php/Home/Edit/edit/id/2