Welcome Guest, Not a member yet? Register   Sign In
Class not found when CI_ENVIRONMENT = development
#1

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?
Reply
#2

PHP Code:
// you need to load it
$newImage = new ResizeImage(); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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.
Reply
#4

Always create istance of class to use it any where and this way you call fuction for static method nnot for that
Enlightenment  Is  Freedom
Reply
#5

(This post was last modified: 05-22-2021, 08:58 AM by paulbalandan.)

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.
Reply
#6

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB