kirillemko / yii-ci-integration
Kogo dostal codeigniter no net shansov yiti
Installs: 1 021
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
- cebe/assetfree-yii2: ^2.0
- yidas/codeigniter-psr4-autoload: ^1.0
This package is auto-updated.
Last update: 2025-03-26 18:43:08 UTC
README
Installation
The preferred way to install this extension is through composer.
Either run
composer require kirillemko/yii-ci-integration
or add
"kirillemko/yii-ci-integration": "*"
to the require section of your composer.json.
Usage
Create yii_config.php file in your CodeIgniter config folder
<?php
include(APPPATH . '/config/database.php');
$commonConfig = [
'id' => 'yii_sub_app',
'basePath' => dirname(__DIR__),
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=' . $db['default']['hostname'] . ';dbname=' . $db['default']['database'] . '',
'username' => $db['default']['username'],
'password' => $db['default']['password'],
'charset' => 'utf8',
],
],
];
$webOnlyConfig = [
'components' => [
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
]
];
$consoleOnlyConfig = [
'bootstrap' => ['gii'],
'modules' => [
'gii' => [
'class' => 'yii\gii\Module',
],
],
];
if (defined('APP_CONSOLE')) {
return array_merge_recursive($commonConfig, $consoleOnlyConfig);
}
return array_merge_recursive($commonConfig, $webOnlyConfig);
To sync Yii User component with CodeIgniter one, please register my user component, set identityClass the same way you make it in Yii and implement ExternalIdentityInterface in this class
'components' => [
...
'user' => [
'class' => 'kirillemko\yci\components\user\User',
'identityClass' => 'App\domain\common\models\Users',
],
class Users extends ActiveRecord implements ExternalIdentityInterface
{
public function getId() {
return $this->id;
}
public static function getIdentity() {
$ci = &get_instance();
$user_id = $ci->ion_auth->get_user_id();
if( !$user_id ){
return null;
}
return static::findOne($user_id);
}
}
Finally, load Yii core where needed
require_once(APPPATH . '../vendor/yiisoft/yii2/Yii.php');
$yiiConfig = require APPPATH . 'config/yii_config.php';
new \yii\web\Application($yiiConfig); // Do NOT call run() here
To run Yii migrtions run
vendor\kirillemko\yii-ci-integration\src\yii migrate
Credits
Authors: Kirill Emelianenko, Evgeny Starodubcev
Email: kirill.emko@mail.ru