cakephp 与 mongodb 集成教程
没有mongodb的测试环境的可以在本地安装个mongodb服务,这里有mongodb在windows下的图文安装教程。
php 默认没有开启mongodb扩展,需要手动到官网上下载mongo扩展,在这里找到适合你系统的mongo扩展,将其解压放入到php环境指定的ext目录下,同时在php.ini文件中加入
extension=php_mongo.dll
重启apache等服务器后生效.
从github上下载cakephp与mongodb的datasouce,安装在app/plugins/目录下
PS:没有git的同志也不用担心,可以直接下载
下载完成后就可以在database.php中配置mongodb:
var $mongo = array(
‘datasource’ => ‘mongodb.mongodbSource’,
‘database’ => ‘testmongo’,
‘host’ => ‘localhost’,
‘port’ => 27017
);
可以创建一个model在控制器中使用它:
//mongb.php
class Mondb extends AppModel {
var $name = ‘Mondb’;
var $primaryKey = ‘_id’;
var $useDbConfig = ‘mongo’;
function schema() {
$this->_schema = array(
‘_id’ => array(‘type’ => ‘integer’, ‘primary’ => true, ‘length’ => 40),
‘a’ => array(‘type’ => ‘string’),
‘b’ => array(‘type’ => ‘integer’),
);
return $this->_schema;
}
}
?>
那么在控制器中就可以操作mongodb了:
function mongo(){
$this -> loadModel(‘Mondb’);
$res = $this -> Mondb -> save(array(“a”=”test mongodb”,”b”=>time()));
$res = $this -> Mondb -> find(‘all’);
pr($res);
exit;
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
