jamierumbelow/codeigniter-base-model — pull request #107 by cryode (2013-02-25 03:45:35+00:00)
Title: Fix DB connection issue, add supporting documentation.

Unfortunately #104, while having the good idea to give per-model DB connection capabilities, broke the simplest use case of MY_Model:

```php
class Post_model extends MY_Model {}

class Example extends CI_Controller {

public function index()
{
$this->load->database();
$this->load->model('post_model', 'posts');

$posts = $this->posts->get_all();
}
}
```

Result:
> Fatal error: Call to a member function get() on a non-object in /application/core/MY_Model.php on line 216

The problem is this chunk of code:
```php
if (!$this->_db)
{
$this->_database = $this->load->database();
}
```

`$this->load->database()` won't return anything except `FALSE` or `NULL`, so no DB connection is being assigned to `$_database`, when we kind of need one! :)

I've revised the code to default to the original global database property, loading it if necessary. I've also updated the comments and README.md to appropriately describe the functionality, including the ability to pass a full `$config` array of DB settings if desired.

**The unit testing right now kind of sucks.** From what I can tell, the only reason `$_database` is public is so unit testing can work properly, and that's dumb. Unfortunately I'm not really well-versed in unit testing, and CI isn't exactly the easiest thing to write tests for, so I didn't think of a suitable fix right away. I didn't want to wait for that to submit this PR, given the fatal error nature of it.