Skip to content

Instantly share code, notes, and snippets.

@chabibnr
Last active March 5, 2022 00:53
Show Gist options
  • Save chabibnr/59d068a8b7296066b678618e174a6573 to your computer and use it in GitHub Desktop.
Save chabibnr/59d068a8b7296066b678618e174a6573 to your computer and use it in GitHub Desktop.
Library Yii2 for Codeigniter
/*
| -------------------------------------------------------------------
| Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in system/libraries/ or your
| application/libraries/ directory, with the addition of the
| 'database' library, which is somewhat of a special case.
|
| Prototype:
|
| $autoload['libraries'] = array('database', 'email', 'session');
|
| You can also supply an alternative library name to be assigned
| in the controller:
|
| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array('Yii_Library');
Download archive yii2 framework : https://github.com/yiisoft/yii2-framework/archive/2.0.10.zip
masukan ke third_party : application\third_party\yii2
<?php
define('YII_ENABLE_ERROR_HANDLER', false);
/**
* Class Yii_Library
* @package Libraries
*/
class Yii_Library
{
/**
* @var array $db_config
*/
private $db_config;
/**
* @var string $yii_path
*/
private $yii_path = 'third_party/yii2/Yii.php';
/**
* Yii_Library constructor.
*/
public function __construct()
{
/**
* @var array $db
* @var string $active_group
*/
require_once APPPATH.'config/database.php';
$this->db_config = $db[$active_group];
$this->init();
}
/**
* @return void
*/
public function init(){
require APPPATH . $this->yii_path;
new yii\web\Application([
'id' => 'ci-app',
'basePath' => APPPATH,
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host='.$this->db_config['hostname'].';dbname='. $this->db_config['database'],
'username' => $this->db_config['username'],
'password' => $this->db_config['password'],
'charset' => 'utf8',
'tablePrefix' => $this->db_config['dbprefix']
]
]
]);
}
}
@agungsijawir
Copy link

much better

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