tlg05 / cakephp-neo4j
Neo4j 数据源为 CakePHP
dev-master
2017-12-20 02:06 UTC
Requires
- php: >=5.3.0
- composer/installers: *
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-09-29 04:49:36 UTC
README
要求
- PHP5
- CakePHP >= 2.2.5
安装
- 此数据源通过 RESTful API 发送 neo4j 请求。因此不需要 Neo4j 的 PHP 驱动程序。
- 此项目是一个标准的 CakePHP 插件,可以像其他插件一样安装。
将仓库放在插件文件夹下
cd my/app/Plugin
git clone git://github.com/tlg05/cakephp-neo4j.git Neo4j
在 bootstrap.php 中加载插件
CakePlugin::load("Neo4j");
在 database.php 中提供数据库服务器信息
class DATABASE_CONFIG {
public $neo4j = array(
'datasource' => 'Neo4j.Neo4jSource',
'host' => 'localhost',
'port' => 34618,
'login' => 'neo4j',
'password' => 'password'
);
public $test_neo4j = array(
'datasource' => 'Neo4j.Neo4jSource',
'host' => 'localhost',
'port' => 33110,
'login' => 'neo4j',
'password' => 'password'
);
}
注意
- 请确保模型文件使用无模式行为。
- 有两个模型可以扩展:节点和关系。这两种模型通过属性 $modelType 区分。
工作原理
测试用例包含详细的使用示例。
节点可以像正常的 CakePHP 数据一样管理。
$data = array(
'title' => 'test1',
'body' => 'aaaa',
'text' => 'bbbb'
);
$this->Post->create();
$this->Post->save($data);
$data = $this->Post->find('all');
关系是特殊的。我们需要提供关系的起始节点、结束节点和属性。 关系的属性需要放在 properties 标签下,而不是数据的根级别
$data = array(
'start' => 'Post',
'end' => 'Writer',
'conditions' => array(
'start.title' => 'The Old Man and the Sea',
'end.name' => 'Hemingway'
),
'properties' => array(
'note' => ‘Hemingway writes The Old Man and the Sea'
)
);
$this->Write->create();
$this->Write->save($data3, array("atomic" => false));
尚不支持数据关联。
作者
Ligeng Te tlgnewlife@gmail.com