tp操作mongodb数据库之简易留言板
来源:互联网 发布:ubuntu ssh root 编辑:程序博客网 时间:2024/05/06 04:05
tp操作mongodb数据库之简易留言板
包含的常规操作:数据增加,数据修改,数据删除。
conf
<?php
return array(
'db_type' => 'mongo',
'db_host' => 'localhost',
'db_port' => '27017',
'db_Name' => 'test',
);
controller
<?php
namespace Notes\Controller;
use Think\Controller;
/**
* 文档: IndexController
* @作者: gongmingshi
* @邮件地址: gongmingshi@qq.com
*/
class IndexController extends Controller {
public function index() {
$m = D('notes');
if (isset($_REQUEST['m'])) {
$w['_id'] = I('request.m');
$dd = $m->where($w)->find();
if (isset($_REQUEST['i'])) {
$this->assign($dd['replay'][$_REQUEST['i']]);
} else {
$this->assign($dd);
}
//var_dump($dd);
}
$d = $m->select();
$this->assign("data", $d);
$this->display();
}
public function add() {
$m = D('notes');
if (isset($_POST['m'])) {
$w['_id'] = $_POST['m'];
if (isset($_POST[i])) {
$i = I('post.i');
$d = array("replay." . $i . ".title" => I('post.title'), "replay." . $i . ".content" => I('post.content'));
} else {
$d = array("title" => I('post.title'), "content" => I('post.content'));
}
$r = $m->where($w)->save($d);
if ($r) {
$this->success("回复成功修改", __CONTROLLER__ . "/index");
}
} elseif (isset($_POST['replay'])) {
$w['_id'] = I('post.replay');
$d["replay"] = array("push", I('post.'));
$r = $m->where($w)->save($d);
if ($r) {
$this->success("回复成功", __CONTROLLER__ . "/index");
}
} else {
if (!0 == count(array_filter(I('post.')))) {
$d = $m->add($_POST);
if ($d) {
$this->success("成功插入", __CONTROLLER__ . "/index");
}
} else {
$this->error("无数据插入");
}
}
}
public function mydel() {
$m = D('notes');
$w['_id'] = I('request.id');
if (isset($_REQUEST['i'])) {
$d["replay"] = array("pop", I('request.i'));
$r = $m->where($w)->save($d);
if ($r) {
$this->success("回复成功删除", __CONTROLLER__ . "/index");
}
} else {
$dd = $m->where($w)->delete();
if ($dd) {
$this->success("留言成功删除", __CONTROLLER__ . "/index");
}
}
}
}
view:略
- tp操作mongodb数据库之简易留言板
- yii简易留言板 AR操作数据库
- 简易留言板(数据库交互)
- mongoDB之数据库操作
- 简易留言板
- 简易留言板
- PHP操作MongoDB创建简单留言板
- tp中数据库相关操作
- MongoDB:MongoDB数据库操作
- MongoDB简易安装与操作
- NoSql之MongoDB实现数据库数据操作
- SSH整合之入门级例子:简易留言板(完整源码)
- PHP简易留言板
- WebStorage简易Web留言板
- PHP简易留言板
- Vue制作简易留言板!
- vue简易留言板
- [React]简易留言板
- 转: 实现自己的类加载时,重写方法loadClass与findClass的区别
- hdu 1425简单hash
- android 新线程的生成及信息接收
- 问题驱动的软件测试设计_问题总结
- 数据结构与算法系列-图
- tp操作mongodb数据库之简易留言板
- MyEclipse8.5安装后怎么没有Eclipse文件夹啊
- 关于 账号密码等隐私信息的存储-------KeychainItemWrapper和SFHFKeychainUtils
- 14.6 反射:运行时的类信息
- android 应用开发 ---- widget
- Android使用自定义控件的方法
- sql server中嵌套事务
- 双slave的server_uuid相同问题
- 上半年(2014)那些事