Clarity Posted October 31, 2022 Share Posted October 31, 2022 Hello everyone! I'm using "use" statement in controller like this: <?php namespace Wireframe\Component\MyComponent; use Wireframe\Lib\Utils; class MyComponent extends \Wireframe\Component { ... } Then it works in component view iff I write use Wireframe\Lib\Utils; in component view, otherwise I get an error: Class "ProcessWire\Utils" not found. Can you please tell me if it is possible to use utility class in component view if it is explicitly used only in component controller? Link to comment Share on other sites More sharing options...
teppo Posted November 1, 2022 Share Posted November 1, 2022 I don't think there's any obvious way around this: PHP considers namespace declarations and use statements (aliasing/importing) on a per file basis. Quote Importing rules are per file basis, meaning included files will NOT inherit the parent file's importing rules. (Technically this could be achieved by some sort of file complication scheme, but in my opinion issues with that approach would easily outweight potential benefits.) It's a matter of preference of course, but I often use full namespace (e.g. \Wireframe\Lib\Utils::some_method()) in my views. Just feels more intuitive to me, even if it does add a bit of verbosity ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now