I have a Symfony bundle where I will have to use a custom class. This class does not have to be accessible from all the website, but just in a controller of this bundle. I have seen a few solutions relative to the vendors, but this is quite heavy and not necessary in my case. Does someone have a simpler solution?
This is what namespaces are for.
From php.net:
What are namespaces? In the broadest definition namespaces are a way of encapsulating items.
Simply put, include your namespace at the top of your custom class.
src/Acme/DemoBundle/Model/MyClass.php
<?php
namespace Acme\DemoBundle\Model;
class MyClass { // ...
and use it in your Controller:
src/Acme/SomeOtherBundle/Controller/DefaultController.php
<?php
namespace Acme\SomeOtherBundle\Controller;
// ...
use Acme\DemoBundle\Model\MyClass; # can be used in any class in any bundle
// ...
class DefaultController extends Controller { // ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With