Last active
December 13, 2018 05:30
-
-
Save damulhan/82c7ca5b0bddd79ef9cde1ec13604e8f to your computer and use it in GitHub Desktop.
Revisions
-
damulhan revised this gist
Dec 13, 2018 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,5 +43,17 @@ public function index() } } /* --------- input() output prints ------- Name: Elvis Presley Home: 12025554444 Mobile: 18029997777 Name: John Green Home: 120233334877 Name: Joseph Hamilton ------------------------------- */ } -
damulhan revised this gist
Dec 13, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public function index() foreach ( $persons as $person ) { echo "Name: " . $person->name . '<br><br>'; $telephones = $person->telephone; #print_r($telephones); foreach ( $telephones as $telephone ) { echo $telephone->telephone_type->type . ': ' . $telephone->telephone . '<br>'; -
damulhan revised this gist
Dec 13, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ <?php defined('BASEPATH') OR exit('No direct script access allowed'); /* Example code */ class Welcome extends CI_Controller { /** @@ -24,8 +25,7 @@ public function __construct() { $this->load->model('Telephone'); $this->load->model('Telephone_type'); } public function index() { -
damulhan revised this gist
Dec 13, 2018 . No changes.There are no files selected for viewing
-
damulhan revised this gist
Dec 13, 2018 . 2 changed files with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Events\Dispatcher; /* -- codeigniters' database setting $active_group = 'default'; $query_builder = TRUE; @@ -31,6 +32,7 @@ 'failover' => array(), 'save_queries' => TRUE ); */ ########################################################################### File renamed without changes. -
damulhan revised this gist
Oct 26, 2016 . 2 changed files with 4 additions and 33 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,38 +1,6 @@ <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { /** This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ ## if you want to load eloquent model from global context; ## $ci_path = realpath(__DIR__ . 'codeigniter_path') . '/'; ## $ci_system_path = $ci_path . 'system/'; ## define('BASEPATH', str_replace('\\', '/', $ci_system_path)); -
damulhan revised this gist
Oct 26, 2016 . 3 changed files with 55 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -90,30 +90,3 @@ $capsule->setEventDispatcher($events); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,38 @@ <?php defined('BASEPATH') OR exit('No direct script access allowed'); ############# # Eloquent loader ## $ci_path = realpath(__DIR__) . '/../../'; ## $ci_system_path = $ci_path . 'system/'; ## define('BASEPATH', str_replace('\\', '/', $ci_system_path)); function load_model($model) { global $ci_path; $_ci_model_paths = [ $ci_path . 'application/' ]; $model = ucfirst(strtolower($model)); $path = ''; foreach ($_ci_model_paths as $mod_path) { if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) { continue; } require_once($mod_path.'models/'.$path.$model.'.php'); $_ci_models[] = $name; return new $model(); } } ############# class Welcome extends CI_Controller { /** This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ ## $ci_path = realpath(__DIR__ . '/../../modules/ci/') . '/'; ## $ci_system_path = $ci_path . 'system/'; ## define('BASEPATH', str_replace('\\', '/', $ci_system_path)); function load_model($model) { global $ci_path; $_ci_model_paths = [ $ci_path . 'application/' ]; $model = ucfirst(strtolower($model)); $path = ''; foreach ($_ci_model_paths as $mod_path) { if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) { continue; } require_once($mod_path.'models/'.$path.$model.'.php'); $_ci_models[] = $name; return new $model(); } } -
damulhan revised this gist
Oct 26, 2016 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -89,3 +89,31 @@ }); $capsule->setEventDispatcher($events); ############# ## $ci_path = realpath(__DIR__ . '/../../modules/ci/') . '/'; ## $ci_system_path = $ci_path . 'system/'; ## define('BASEPATH', str_replace('\\', '/', $ci_system_path)); function load_model($model) { global $ci_path; $_ci_model_paths = [ $ci_path . 'application/' ]; $model = ucfirst(strtolower($model)); $path = ''; foreach ($_ci_model_paths as $mod_path) { if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) { continue; } require_once($mod_path.'models/'.$path.$model.'.php'); $_ci_models[] = $name; return new $model(); } } -
damulhan revised this gist
Oct 26, 2016 . 1 changed file with 0 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,22 +0,0 @@ -
damulhan renamed this gist
Oct 26, 2016 . 1 changed file with 26 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,8 @@ ### Sample models # models/Telephone.php defined('BASEPATH') OR exit('No direct script access allowed'); use Illuminate\Database\Eloquent\Model as Eloquent; @@ -25,10 +27,12 @@ function telephone_type() { } //////////////////////////////////////////////////////////////////////////// <?php # models/Person.php defined('BASEPATH') OR exit('No direct script access allowed'); use Illuminate\Database\Eloquent\Model as Eloquent; @@ -45,5 +49,26 @@ function telephone() { } } //////////////////////////////////////////////////////////////////////////// <?php # models/Telephone_type.php defined('BASEPATH') OR exit('No direct script access allowed'); use Illuminate\Database\Eloquent\Model as Eloquent; class Telephone_type extends Eloquent { public $timestamps = true; protected $table = 'test_telephone_type'; protected $primaryKey = 'id'; protected $fillable = ['type']; function telephone() { return $this->belongsTo('Telephone'); } } -
damulhan revised this gist
Oct 26, 2016 . 1 changed file with 39 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ CREATE TABLE IF NOT EXISTS `test_person` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; INSERT INTO `test_person` (`id`, `name`) VALUES (1, 'Elvis Presley'), (2, 'John Green'), (3, 'Joseph Hamilton'); CREATE TABLE IF NOT EXISTS `test_telephone` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `person_id` bigint(20) NOT NULL, `telephone_type_id` bigint(20) NOT NULL, `telephone` bigint(14) NOT NULL, PRIMARY KEY (`id`), KEY `fk_telephone_person_idx` (`person_id`), KEY `fk_telephone_telephone_type1_idx` (`telephone_type_id`), CONSTRAINT `fk_telephone_person` FOREIGN KEY (`person_id`) REFERENCES `test_person` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_telephone_telephone_type1` FOREIGN KEY (`telephone_type_id`) REFERENCES `test_telephone_type` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; INSERT INTO `test_telephone` (`id`, `person_id`, `telephone_type_id`, `telephone`) VALUES (1, 1, 1, 12025554444), (2, 1, 3, 18029997777), (3, 2, 1, 120233334877); CREATE TABLE IF NOT EXISTS `test_telephone_type` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `type` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; INSERT INTO `test_telephone_type` (`id`, `type`) VALUES (1, 'Home'), (2, 'Work'), (3, 'Mobile'); -
damulhan revised this gist
Oct 22, 2016 . 2 changed files with 69 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/<method_name> * @see http://codeigniter.com/user_guide/general/urls.html */ public function __construct() { parent::__construct(); $this->load->model('Person'); $this->load->model('Telephone'); $this->load->model('Telephone_type'); } public function index() { $persons = Person::all(); foreach ( $persons as $person ) { echo "Name: " . $person->name . '<br><br>'; $telephones = $person->telephone; print_r($telephones); foreach ( $telephones as $telephone ) { echo $telephone->telephone_type->type . ': ' . $telephone->telephone . '<br>'; } echo '<hr>'; } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,3 +25,25 @@ function telephone_type() { } ///////////////// <?php defined('BASEPATH') OR exit('No direct script access allowed'); use Illuminate\Database\Eloquent\Model as Eloquent; class Person extends Eloquent { public $timestamps = false; protected $table = 'test_person'; protected $primaryKey = 'id'; protected $fillable = ['name']; function telephone() { return $this->hasMany('Telephone', 'person_id'); } } -
damulhan created this gist
Oct 22, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ { "require": { "illuminate/database": "5.0.28", "illuminate/events": "5.0.28", } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,91 @@ # configs/database.php /* * Start Implementation of Eloquent */ use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Events\Dispatcher; $active_group = 'default'; $query_builder = TRUE; $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => '', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => TRUE, 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE ); ########################################################################### /* * Create a new capsule */ $capsule = new Capsule; $capsule->addConnection([ 'driver' => 'mysql', 'host' => $db['default']['hostname'], 'database' => $db['default']['database'], 'username' => $db['default']['username'], 'password' => $db['default']['password'], 'charset' => $db['default']['char_set'], 'collation' => $db['default']['dbcollat'], 'prefix' => $db['default']['dbprefix'], ]); // Make this Capsule instance available globally via static methods... (optional) $capsule->setAsGlobal(); // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher()) $capsule->bootEloquent(); /* * Add Events to CodeIgniter adapted in our own way * LINK: http://jamieonsoftware.com/post/90299647695/using-eloquent-orm-inside-codeigniter-with-added */ $events = new Dispatcher; $events->listen('illuminate.query', function($query, $bindings, $time, $name) { // Format binding data for sql insertion foreach ($bindings as $i => $binding) { if ($binding instanceof \DateTime) { $bindings[$i] = $binding->format('\'Y-m-d H:i:s\''); } else if (is_string($binding)) { $bindings[$i] = "'$binding'"; } } // Insert bindings into query $query = str_replace(array('%', '?'), array('%%', '%s'), $query); $query = vsprintf($query, $bindings); // Add it into CodeIgniter $db =& get_instance()->db; $db->query_times[] = $time; $db->queries[] = $query; }); $capsule->setEventDispatcher($events); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ <?php ### Sample models defined('BASEPATH') OR exit('No direct script access allowed'); use Illuminate\Database\Eloquent\Model as Eloquent; class Telephone extends Eloquent { public $timestamps = true; protected $table = 'test_telephone'; protected $primaryKey = 'id'; protected $fillable = [ 'person_id', 'telephone_type_id']; function person() { return $this->belongsTo('Person'); } function telephone_type() { return $this->hasOne('Telephone_type', 'id', 'telephone_type_id'); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ <?php ### Sample models defined('BASEPATH') OR exit('No direct script access allowed'); use Illuminate\Database\Eloquent\Model as Eloquent; class Telephone_type extends Eloquent { public $timestamps = true; protected $table = 'test_telephone_type'; protected $primaryKey = 'id'; protected $fillable = ['type']; function telephone() { return $this->belongsTo('Telephone'); } }