1. Go to this page and download the library: Download slavcodev/yii2-yii-bridge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
slavcodev / yii2-yii-bridge example snippets
// Define project directories.
$rootPath = dirname(dirname(__DIR__));
/**
* Include composer autoloader
* @var \Composer\Autoload\ClassLoader $loader Registered composer autoloader.
*/
$loader = until v1.1.17 will released.
// You need version of file after this commit
// @link https://github.com/yiisoft/yii/commit/e08e47ce3ce503b5eb92f9f9bd14d36ac07e1ae9
// define('YII1_BASE_PATH', $rootPath . '/vendor/slavcodev/yii2-yii-bridge/YiiBase.php');
// Include Yii bridge class file.
// Access new application
echo Yii::$app->user->id;
// Access old application
echo Yii::app()->user->id;
// Use Yii2 grid, data provider with Yii1 ActiveRecords
echo yii\grid\GridView::widget([
'dataProvider' => new \yii\data\ArrayDataProvider([
'allModels' => User::model()->with('address.country')->findAll(),
]),
'columns' => [
['attribute' => 'id'],
['attribute' => 'name'],
['attribute' => 'address.country.name'],
]
]);
// Save Yii1 AR in Yii2 controller
public function actionCreate()
{
$user = new User();
if ($data = Yii::app()->request->getPost(CHtml::modelName($user))) {
$model->attributes = $data;
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', [
'model' => $user,
]);
}
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.