You’re showing a bit of template code but the error doesn’t look related to that.
The error is saying there is a missing Controller
Controller class `Img` could not be found.
This is being thrown from ...cakephp\src\Controller\ControllerFactory.php. That and the stack trace suggest to me that you’re still trying to parse the Request.
Do you have an ImgController? I can see from the link in your template you have a Dogs controller…
I’m not sure how you’re getting a request to an Img controller but it doesn’t look like the template code is playing a role. Maybe some other Controller code is failing and redirecting in an unexpected way?
Right. So it’s the request from the browser to get the image…
The reason for that is not jumping out. Are there any clues in the page source from the browser? What does the link tag and its child image tag look like?
That is the expected and intended behavior, nothing wrong with it. The default application template’s Apache rewrite rules will make Apache directly serve existing physical files, without actually hitting your application code.
In case no physical file exists, the rewrite rules will pass the request to the application, just like any other request, where the app will then try to look up plugin assets or match a route, and throw a 404 if neither exists, which is a signal for the client that no such file exists, neither a physical one, nor one served by application code.
If you don’t want these exceptions to be logged, then you can add the \Cake\Http\Exception\NotFoundException\Cake\Http\Exception\MissingControllerException to the error handler’s skipLog configuration. This should usually be exclusive to the production environment though.
Yeah, sorry, I copy-pasta’d the wrong name, of course it’s MissingControllerException.
There is no such distinction, a missing controller is a missing controller, no matter what kind of resource the client was possibly looking for. Having CakePHP try to guess what the resource might be would open a whole new can of worms that nobody wants do deal with.
You could of course create your own extended error handler that analyzes the request URL and skips exceptions based on that, but I’m not sure that it’s worth the hassle.
Personally I usually just skip MissingController/Action (or MissingRoute in case no fallback routes exist) and most Http exceptions for public apps in production, as otherwise the logs just get clogged with noise by all the bots visiting non-existent/protected endpoints.