thinkphp跳转技巧
thinkphp吧
全部回复
仅看楼主
level 2
寒小煮ლ 楼主
制作一个初始页面跳转的代码1
思路是用到什么先传什么,添加东西看条件:
public function lst(){
$book = D('book');
$list = $book->where('status=1')->order('sort asc')->select();
$this->assign('list',$list);
$this->display('list');
}
public function book_add()
{
if ($_POST) {
$book = D('book');
$book->create();
$book->created_at = date("Y-m-d H:i:s");
$book->updated_at = date("Y-m-d H:i:s");
$res = $book->add();
if ($res) {
$this->success('添加成功', lst);
} else {
$this->error('添加失败');
}
}else {
$this->display('book_add');
}
}
public function detail(){
// echo 'i am param'."<br/>";
// echo 'i am get'.$_GET['id'];
$id = $_GET['id'];
$book = M('book')->find($id);
$digest = D('digest');
// var_dump($_GET);die;
M('book')->where('id='.$id)->setInc('clicks');
// echo '<pre>';var_dump($id);die;
// $name = $book['name'];
// var_dump($name);die;
// $book->name = I('post.name');
// $book->author = I('post.author');
// $book->clicks =I('post.clicks');find都有了不用再找了
$book->created_at = date("Y-m-d H:i:s");
$ary_where = array();
$ary_where['bookid'] = $id;
// echo '<pre>';var_dump($digest);die;
$res = $digest->where('status=1')->where($ary_where)->order('created_at asc')->select();
$this->assign('res',$res);
$this->assign('book', $book);
$this->display('detail');
}
制作一个初始页面的代码2.
class IndexController extends Controller
{
public function index()
{
$book = M('book');
$res = $book->where('status=1')->order('sort asc')->select();
$this->assign('res', $res);
$this->display('index');
}
public function addBook()
{
if ($_POST) {
$book = M('book');
$book->create();
$book->created_at = date('Y-m-d H:i:s');
$book->updated_at = date('Y-m-d H:i:s');
$res = $book->add();
if ($res) {
$this->success('添加书籍成功', __CONTROLLER__ . '/index');
} else {
return error('添加书籍失败');
}
} else {
$this->display('book_add');
}
}
//详情
public function showDetail($id)
{
$book = M('book')->find($id);
$details = M('digest');
$detail = $details->where("bookid=" . $id)->order('created_at asc')->select();
M('book')->where('id='.$id)->setInc('clicks');//setInc为递增。
$this->assign('detail', $detail);
$this->assign('book', $book);
$this->display('detail');
}
2017年10月29日 22点10分 1
1