'Class X not found' error |
Code: <?php namespace App\Libraries; When I instantiate this class I get a 'Class App\Libraries\PDO not found' error. Why? PDO is enabled. I'm using PHP 7. Why is it looking in App\Libraries?
Simpler is always better
Try $db = new \PDO ...
You have namespaced your class, so you should expect such things.
Thanks, It appears that sessions, redirects, validation, helpers, and libraries all work. I'm going to use CI4 for my next project. Just got to get used to using namespaces.
Simpler is always better
You're forgetting about a how namespaces work. Since that file defined in namespace App\Libraries, all other classes will be assumed to be in that namespace unless other wise specified. Since you don't have anything to tell it otherwise, it's looking for PDO within the current namespace, App\Libraries. There are two solutions:
1. Prepend a backslash to PDO so it knows to look in the "root" namespace. Code: $db = new \PDO(...); 2. Tell it you're going to use that class at the top of file: Code: use PDO; (04-22-2017, 09:52 PM)donpwinston Wrote: CI 4 is not yet even in beta . Think twice before you do that. Best VPS Hosting : Digital Ocean
|
Welcome Guest, Not a member yet? Register Sign In |