我正在使用 Kohana MVC 框架。我想添加一个可与 PHPCassa 对象(Cassandra NoSQL)一起使用的模块。
问题是,当我创建对象时,我拥有它的所有属性,并且可以在构造中与它进行交互,但是当我从不同的地方创建它时,它会作为空对象返回。
我确信我错过了一些东西,因为我对 OOP 很陌生。请帮帮我。
模块文件
<?php
// Loading cassandra libraries, tried to load them here, did not help
//require 'application/modules/cassandra/lib/connection.php';
//require 'application/modules/cassandra/lib/columnfamily.php';
class Cassandra {
function __construct($columnFamily) {
// Loading cassandra libraries
require 'application/modules/cassandra/lib/connection.php';
require 'application/modules/cassandra/lib/columnfamily.php';
$pool = new ConnectionPool('localhost');
$cf = new ColumnFamily($pool, $columnFamily);
// print_r($cf); // This will print object with all the proporties that I can use
return $cf;
}
将加载模块并创建空对象的类
<?php
class Controller_Main extends Controller {
public function action_index() {
$a = new Cassandra('timeline');
echo '<pre>';
print_r($a); // This will print out empty Cassandra object
die();
//$this->response->body('hello, world!');
}
}