I am using Kohana MVC framework. I want to add a module that will work with PHPCassa object (Cassandra NoSQL).
Problem is that when I create the object I have all it’s properties and I can interact with it in construct, but when I create it from different place it’s returning as empty object.
I’m sure that I am missing something since I’m relatevely new to OOP. Please help me out here.
Module file
<?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;
}
Class that will load the module and will create empty object
<?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!');
}
}
Doing it wrong way , you are creating two object in constructor , one the
Cassandraobject and the other isColumnFamilyand obviously thenew Cassandra('timeline');will return theCassandraobject.Try this way :
And use it :