Skip to content

Instantly share code, notes, and snippets.

@nshontz
Created July 12, 2012 17:18
Show Gist options
  • Save nshontz/3099448 to your computer and use it in GitHub Desktop.
Save nshontz/3099448 to your computer and use it in GitHub Desktop.
CI Mongo
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library(array('parser'));
$this->load->spark('cimongo/1.3.0');
}
function index() {
$this->cimongo->insert("monkies", array(
array("name" => "Bob", "species" => "Crab-eating Macaque"),
array("name" => "Sam", "species" => "Crab-eating Macaque"),
array("name" => "Sally", "species" => "Common Squirrel Monkey"),
));
$this->data['monkies'] = $this->cimongo->where('species', "Crab-eating Macaque")->get('monkies');
$this->data['template']["content"] = $this->load->view(__FUNCTION__, $this->data, true);
$this->parser->parse('template/utility', $this->data['template']);
}
}
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined property: Home::$cimongo</p>
<p>Filename: controllers/home.php</p>
<p>Line Number: 19</p>
</div>
Fatal error: Call to a member function insert() on a non-object in /var/www/html/apps/mongo/application/controllers/home.php on line 19
Call Stack:
0.0000 637368 1. {main}() /var/www/html/apps/mongo/index.php:0
0.0002 640032 2. require_once('/var/www/html/codeigniter/ci2.1.2/core/CodeIgniter.php') /var/www/html/apps/mongo/index.php:232
0.0031 1110272 3. call_user_func_array() /var/www/html/codeigniter/ci2.1.2/core/CodeIgniter.php:359
0.0031 1110408 4. Home->index() /var/www/html/codeigniter/ci2.1.2/core/CodeIgniter.php:0
@nshontz
Copy link
Author

nshontz commented Jul 12, 2012

If I change the version to one that it doesn't exist it complains, so it seems to be loading the spark.

@nshontz
Copy link
Author

nshontz commented Jul 12, 2012

I got it fixed by calling the spark, and then loading the library:

    $this->load->spark('cimongo/1.3.0');
    $this->load->library(array('parser','cimongo'));

i'm not sure this is "right" but it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment