CodeIgniter Forums
Services - 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: Services (/showthread.php?tid=73585)



Services - Piotr - 05-12-2019

Hello

I have GetImageInfo function in my model but i get error:

Class 'App\Models\Config\Services' not found



PHP Code:
$info Config\Services::image()
            ->withFile($file_path)
            ->getFile()
            ->getProperties(true); 


How to use services in model?

I found error... solution is:

PHP Code:
$img = \CodeIgniter\Config\Services::image()
            ->
withFile($file_path)
            ->
getFile()
            ->
getProperties(true); 



RE: Services - kilishan - 05-12-2019

I don't recommend using the \CodeIgniter\Config\Services. Just use \Config\Services. It has special features that will life easier down the road as you continue to use it.


RE: Services - MGatner - 05-14-2019

@Piotr you were on the right track originally! PHP expects unspecified namespaces within classes to be relative to that class' namespace, hence why it was looking for "App\Models\Config\Services" in your model. As kilishan suggests, specifying the "\" prevents it from being relative and gets you to the right namespace.