Class 'frontend\controllers\ZipArchive' not found

i have an error when try to make file zip and download it. the class zip archive not found. but when i try it with simple php code it’s work. i use xampp 7 and the zip class was include in php when instal xampp. but in yii2 it’s error.



this my class download in my controller

public function actionDownload()


        $zipnam="QR Code ".Yii::$app->user->identity->username; 





        $filestozip = $file; // FILES ARRAY TO ZIP

        $dir = trim($dir); // DIR NAME TO MOVE THE ZIPPED FILES

        $zipnam = trim($zipnam);

        $zip = new ZipArchive();

        $files = $filestozip;

        $zip_name = $zipnam.".zip";

        $fizip = $dir.$zip_name;

        if($zip->open($fizip, ZipArchive::CREATE) === TRUE) {

            foreach ($files as $fl) {


                $zip->addFromString(basename($fl),  file_get_contents($fl));

                // $zip= $zip+$fl;

                if($del === TRUE) {






            return TRUE;

        } else { $zip->close(); return FALSE;}


is there something i forgot to include?

Either do it like:

$zip = new \ZipArchive();

or place use in class file:

use ZipArchive;

thank you so much… :D