<repo_name>tobidsn/ci3-started<file_sep>/README.md
# ci3-started
Mulai Codeigniter 3 dengan illuminate/database

## Instalasi
* <code>$ git clone https://github.com/huiralb/ci3-started myProject</code>
* Jalankan command line berikut:
```
 $ cd myProject
 $ composer install
 $ php -S localhost:8000
```
* Lihat pada browser dengan url <code>localhost:8000</code>

#### Setup environment
Untuk mengaktifkan debug error secara otomatis pada <code>setting.ini.php</code>
```php
env = development
```
Jika anda bekerja pada local komputer masukkan nilai <code>env</code> dengan <code>development</code>

Ganti <code>env</code> menjadi <code>production</code> untuk environment remote / produksi.

## Database Model
####Untuk menggunakan paket ini:
Sejak anda menjalankan <code>$ composer install</code>, aplikasi sudah terinstall paket database Eloquent dengan bantuan composer, secara spesifik ada di folder <code>app/vendor/illuminate/database</code>.

Pastikan setting koneksi database dengan baik pada file <code>setting.ini.php</code>

### Query Builder
Untuk mengakses model data dari table, code PHP anda kurang lebih terlihat seperti di bawah ini:
```php
	use Illuminate\Database\Capsule\Manager as DB;

	class Selamat_datang extends CI_Controller {

		public function index()
		{
			$users = DB::table('users')->get();

			var_dump($users);

			$this->load->view('welcome_message');
		}
	}
```

### ORM Eloquent Database
* Create file <code>app/Model/User.php</code>
	```php
	<?php
	namespace App\Model;

	use Illuminate\Database\Eloquent\Model;

	class User extends Model {

	}
```
* akses dari controller
```php
$users = \App\Model\User::all();

print_r($users);
<file_sep>/app/modules/backend/controllers/Backend.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Backend extends MX_Controller {

	public function __construct()
	{
		parent::__construct();
	}

	public function index()
	{
		echo "Base page with hmvc";
	}

}

/* End of file Base.php */
/* Location: ./application/controllers/Base.php */<file_sep>/app/libraries/MY_Database.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use Illuminate\Database\Capsule\Manager as DB;

class MY_Database
{
	protected $ci;

	public function __construct()
	{
        $setting = parse_ini_file(FCPATH . "setting.ini.php");

		$capsule = new DB;

		$capsule->addConnection(array(
		    'host'      => $setting['host'],
		    'database'  => $setting['database'],
		    'username'  => $setting['username'],
		    'password'  => $setting['<PASSWORD>'],
		    'driver'    => 'mysql',
		    'charset'   => 'utf8',
		    'collation' => 'utf8_general_ci',
		    'prefix'    => ''
		));

		$capsule->setAsGlobal();
		$capsule->bootEloquent();
	}
	

}<file_sep>/setting.ini.php
;<?php return; ?>
[SQL]

host = localhost
username = root
password = 
database = database

env = development
