CodeIgniter Forums
Class not found when CI_ENVIRONMENT = development - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Class not found when CI_ENVIRONMENT = development (/showthread.php?tid=79279)



Class not found when CI_ENVIRONMENT = development - stephie - 05-21-2021

I have this library app/Libraries/resize_image/ResizeImage.php

Code:
namespace App\Libraries;

class ResizeImage
{ [...] }

I'm using it in a Controller :
Code:
<?php
namespace App\Controllers;

use App\Libraries\ResizeImage;

class ImageUpload extends BaseController
{

   function xyz() {
     [...]
     ResizeImage::smart_resize_image($_FILES['file']['tmp_name'], null, $imgWidth, $imgHeight, false, $resizedFile, false, false, 100, true);
   }
}

Everything works well if I don't set CI_ENVIRONMENT in .env file (or set it to production), but if I set it to development I get this error :
Code:
Class 'App\\Libraries\\ResizeImage' not found

I'm using version 4.1.2

Anyone has a clue please?


RE: Class not found when CI_ENVIRONMENT = development - InsiteFX - 05-21-2021

PHP Code:
// you need to load it
$newImage = new ResizeImage(); 



RE: Class not found when CI_ENVIRONMENT = development - iRedds - 05-21-2021

Show me how you registered the library?

Because app/Libraries/resize_image/ResizeImage.php cannot be accessed through the App\Libraries\ResizeImage namespace without first linking that namespace and file.


RE: Class not found when CI_ENVIRONMENT = development - paliz - 05-22-2021

Always create istance of class to use it any where and this way you call fuction for static method nnot for that


RE: Class not found when CI_ENVIRONMENT = development - paulbalandan - 05-22-2021

Could it be that your class is saved to a directory not respecting PSR-4?

(05-22-2021, 04:00 AM)paliz Wrote: Always create istance of class to use it any where and this way you call fuction for static method nnot for that

Instantiating a class is not needed if you will just need to access a static method.


RE: Class not found when CI_ENVIRONMENT = development - stephie - 06-04-2021

Thanks everyone, I finally got it!

The sub-folder was not name respecting PSR-4 and I needed the create the instance of the classe