1 year ago

#376997

test-img

mightycode Newton

How to upgrade from yii1 to yii2

I have a old YII1 project, version: 1.1.24.

And I want to upgrade to YII2. And of course I have read the official documentation:

https://www.yiiframework.com/doc/guide/2.0/en/intro-upgrade-from-v1

So I have folder name in htdocs with yii and in the folder YII I have the application sdi. and in the folder sdi there is a folder protected with the models, views and controllers in it.

But I have still some problems with upgrading. Because I have the composer.json file like this.

{
  "name": "yiisoft/yii2-imagine",
  "type": "yii2-extension",
  "description": "The Imagine integration for the Yii framework",
  "keywords": [
    "yii2",
    "imagine",
    "image",
    "helper"
  ],
  "license": "BSD-3-Clause",
  "support": {
    "issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Aimagine",
    "forum": "https://forum.yiiframework.com/",
    "wiki": "https://www.yiiframework.com/wiki/",
    "irc": "ircs://irc.libera.chat:6697/yii",
    "source": "https://github.com/yiisoft/yii2"
  },
  "authors": [
    {
      "name": "Antonio Ramirez",
      "email": "amigo.cobos@gmail.com"
    }
  ],
  "require": {
    "yiisoft/yii2": "~2.0.0",
    "imagine/imagine": "v0.5.0"
  },
  "autoload": {
    "psr-4": {
      "yii\\imagine\\": ""
    }
  }
}

But when I do a composer install. I get this message:

Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
Nothing to install, update or remove
Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.
Package padraic/phar-updater is abandoned, you should avoid using it. No replacement was suggested.
Package zendframework/zend-cache is abandoned, you should avoid using it. Use laminas/laminas-cache instead.
Package zendframework/zend-config is abandoned, you should avoid using it. Use laminas/laminas-config instead.
Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.
Package zendframework/zend-filter is abandoned, you should avoid using it. Use laminas/laminas-filter instead.
Package zendframework/zend-hydrator is abandoned, you should avoid using it. Use laminas/laminas-hydrator instead.
Package zendframework/zend-i18n is abandoned, you should avoid using it. Use laminas/laminas-i18n instead.
Package zendframework/zend-json is abandoned, you should avoid using it. Use laminas/laminas-json instead.
Package zendframework/zend-math is abandoned, you should avoid using it. Use laminas/laminas-math instead.
Package zendframework/zend-serializer is abandoned, you should avoid using it. Use laminas/laminas-serializer instead.
Package zendframework/zend-servicemanager is abandoned, you should avoid using it. Use laminas/laminas-servicemanager instead.
Package zendframework/zend-stdlib is abandoned, you should avoid using it. Use laminas/laminas-stdlib instead.
Generating autoload files
7 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

So how to upgrade from yii1 to yii2?

Thank you

I have copied the vendor folder and the Excel in the extensions/phpexcel/Classes.

And I have the class now like this:

$autoload = DIR_ROOT . 'vendor/autoload.php';
require $autoload;

use PhpOffice\PhpSpreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Writer\Xls;
use PhpOffice\PhpSpreadsheet\IOFactory;
 
define('_SET_MEMORY_LIMIT_','1024M');

class Downloader extends CWidget
{
    public function downloadByTask(Task $task)
    {
        $this->createExcel($task, null);
    }

    public function downloadByProject(Project $project)
    {
        $this->createExcel(null, $project, true);
    }

    public function createExcel(Task $task = null, Project $project =null, $projectTitle = false)
    {
        error_reporting(E_ALL);
        ini_set('display_errors', TRUE);
        ini_set('display_startup_errors', TRUE);

        $objPHPExcel = new PhpSpreadsheet\Spreadsheet();

        $default_border = array(
            'style' => \PHPExcel_Style_Border::BORDER_THIN,
            'color' => array('rgb'=>'1006A3')
        );

        $style_header = array(
            'borders' => array(
                'bottom' => $default_border,
                'left' => $default_border,
                'top' => $default_border,
                'right' => $default_border,
            ),
            'fill' => array(
                'type' => \PHPExcel_Style_Fill::FILL_SOLID,
                'color' => array('rgb'=>'E1E0F7'),
            ),
            'font' => array(
                'bold' => true,
                'size' => 16,
            )
        );

        $style_content = array(
            'borders' => array(
                'bottom' => $default_border,
                'left' => $default_border,
                'top' => $default_border,
                'right' => $default_border,
            ),
            'fill' => array(
                'type' => \PHPExcel_Style_Fill::FILL_SOLID,
                'color' => array('rgb'=>'eeeeee'),
            ),
            'font' => array(
                'size' => 12,
            )
        );

        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Zoekterm')
            ->setCellValue('B1', 'Website')
            ->setCellValue('C1', 'Pagina')
            ->setCellValue('D1', 'Paginatitel')
            ->setCellValue('E1', 'Paginabeschrijving')
            ->setCellValue('F1', 'KvK-nummer')
            ->setCellValue('G1', 'Vestigingsnummer')
            ->setCellValue('H1', 'Adresgegevens');
        $objPHPExcel->getActiveSheet()->getStyle('A1:H1')->applyFromArray( $style_header ); // give style to header

        $dataku = [];

        if ($projectTitle == \BoolState::TRUE) {
            foreach ($project->tasks as $task)
                if ($task->status_id == TaskStatus::CLOSED)
                    foreach ($task->activeResults as $result)
                       $dataku[] = [$result->task->search_query, $result->page_url, $result->page_link, $result->page_title, $result->page_description, $result->coc_number, $result->branch_code, $result->address];
        } else {
            foreach ($task->activeResults as $result)
                $dataku[] = [$result->task->search_query, $result->page_url, $result->page_link, $result->page_title, $result->page_description, $result->coc_number, $result->branch_code, $result->address];
        }

        $firststyle='A2';
        for($i=0;$i<count($dataku);$i++)
        {
            $urut=$i+2;
            $search_query='A'.$urut;
            $page_url='B'.$urut;
            $page_link='C'.$urut;
            $page_title='D'.$urut;
            $page_description='E'.$urut;
            $coc_number='F'.$urut;
            $branch_code='G'.$urut;
            $address='H'.$urut;
            $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue($search_query, $dataku[$i][0])
                ->setCellValue($page_url, $dataku[$i][1])
                ->setCellValue($page_link, $dataku[$i][2])
                ->setCellValue($page_title, $dataku[$i][3])
                ->setCellValue($page_description, $dataku[$i][4])
                ->setCellValue($coc_number, $dataku[$i][5])
                ->setCellValue($branch_code, $dataku[$i][6])
                ->setCellValue($address, $dataku[$i][7]);
            $laststyle=$page_description;
        }

        $objPHPExcel->getActiveSheet()->getStyle($firststyle.':'.$laststyle)->applyFromArray( $style_content ); // give style to header

// Rename worksheet
        $objPHPExcel->getActiveSheet()->setTitle('Product');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
        $objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="NVWA HDT '.ucfirst($projectTitle ? $task->project->description : $task->search_query).'.xls"'); // file name of excel
        header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
        header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
        header ('Expires: Mon, 10 Jul 2020 05:00:00 GMT'); // Date in the past
        header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
        header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header ('Pragma: public'); // HTTP/1.0

        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;
    }
}

And I have a autoload.php in the folder vendor.

But I get this error:

require(C:\xampp\htdocs\yii\sdi\vendor/autoload.php): Failed to open stream: No such file or directory

php

yii

yii2

0 Answers

Your Answer

Accepted video resources