Skip to content

Instantly share code, notes, and snippets.

@sjarifHD
Last active November 2, 2016 09:43
Show Gist options
  • Select an option

  • Save sjarifHD/cf26fd5f1c403e66d9684b3a78884e7a to your computer and use it in GitHub Desktop.

Select an option

Save sjarifHD/cf26fd5f1c403e66d9684b3a78884e7a to your computer and use it in GitHub Desktop.
Cdeigniter 3 MY First Setup
<IfModule mod_rewrite.c>
RewriteEngine On
SetEnvIf Host www.yoursite.tld$ CI_ENV=production
SetEnvIf Host test.yoursite.tld$ CI_ENV=testing
SetEnvIf Host localhost$ CI_ENV=development
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
RewriteEngine On
SetEnvIf Host www.yoursite.tld$ CI_ENV=production
#SetEnvIf Host test.yoursite.tld$ CI_ENV=testing
SetEnvIf Host localhost$ CI_ENV=development
RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
// LIBRARY
Rest Controller
https://github.com/chriskacerguis/codeigniter-restserver
http://rizupz.blogspot.co.id/2016/05/membuat-rest-api-dengan-codeigniter.html
Ion Auth
http://benedmunds.com/ion_auth/
http://avenir.ro/authentication-system-with-ion-auth-and-ci3/
----------------------
// CORE
MY_Model
https://github.com/avenirer/CodeIgniter-MY_Model
----------------------
//CONFIG
Matches CLI (lihat gist config.php)
https://github.com/avenirer/codeigniter-matches-cli
//using composer
http://avenir.ro/codeigniter-tutorials/codeigniter-with-composer/
//session database
http://avenir.ro/codeigniter-tutorials/sessions-with-database-in-codeigniter/
-------------------
// Di folder config
buat 3 directory:
-application
--config
---development
-----config.php
-----database.php
-----routes.php
-----ion_auth.php
-----matches.php
---production
----- sama
---testing
----- sama
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Admin_Controller extends MY_Controller
{
// MORE TODO
public function __construct()
{
parent::__construct();
$this->load->library('ion_auth');
if (!$this->ion_auth->logged_in()) {
//redirect them to the login page
redirect('admin/user/login', 'refresh');
}
$current_user = $this->ion_auth->user()->row();
$this->user_id = $current_user->id;
$this->data['current_user'] = $current_user;
$this->data['current_user_menu'] = '';
if ($this->ion_auth->in_group('admin')) {
$this->data['current_user_menu'] = $this->load->view('templates/_parts/user_menu_admin_view.php', NULL, TRUE);
}
$this->data['page_title'] = 'CI App - Dashboard';
}
protected function render($the_view = null, $template = 'admin_master')
{
parent::render($the_view, $template);
}
}
/* End of file Admin_Controller.php */
/* Location: .//home/rieftux/www/html/ci-tes2/kopilet_ci/BaseControllers/Admin_Controller.php */
$autoload['helper'] = array('url');
//BASE URL
$server = 'http://'.$_SERVER['HTTP_HOST'];
$directory = preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])).'/';
$config['base_url'] = $server.$directory;
// OR for use with Matches CLI
$config['base_url'] = '';
//index_page
$config['index_page'] = '';
//COMPOSER
$config['composer_autoload'] = true;
require_once APPPATH.'../vendor/autoload.php';
//Save session di DB (buat dulu tabel sesuai dg nama $config['sess_save_path'] di database
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = false;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = false;
// FOR MATCHES CLI
$config['uri_protocol'] = 'AUTO';
$config['uri_protocol'] = isset($_SERVER['REQUEST_URI']) ? 'PATH_INFO' : 'CLI';
$config[‘migration_enabled’] = TRUE
http://avenir.ro/the-migrations-in-codeigniter-or-how-to-have-a-git-for-your-database/
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class MY_Controller extends CI_Controller
{
// MORE TODO
protected $data = array();
public function __construct()
{
parent::__construct();
$this->data['page_title'] = 'My CodeIgniter App';
$this->data['before_head'] = '';
$this->data['before_body'] = '';
}
protected function render($the_view = null, $template = 'master')
{
if ($template == 'json' || $this->input->is_ajax_request()) {
header('Content-Type: application/json');
echo json_encode($this->data);
} elseif (is_null($template)) {
$this->load->view($the_view, $this->data);
} else {
$this->data['the_view_content'] = (is_null($the_view)) ? '' : $this->load->view($the_view, $this->data, true);
$this->load->view('templates/'.$template.'_view', $this->data);
}
}
}
include_once APPPATH.'core/Admin_Controller.php';
include_once APPPATH.'core/Public_Controller.php';
/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Public_Controller extends MY_Controller {
// MORE TODO
public function __construct()
{
parent::__construct();
echo 'This is from public controller';
}
protected function render($the_view = null, $template = 'public_master')
{
parent::render($the_view, $template);
}
}
/* End of file Public_Controller.php */
/* Location: .//home/rieftux/www/html/ci-tes2/kopilet_ci/BaseControllers/Public_Controller.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment