Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Namespaces / Multi-Moduling

Hi, I have meaning to ask this question for long. We have an application using phalcon framework. We are using social plugins to facilitate users with social network logins like facebook, twitter or google. We have also built an admin panel for this app, for this we implemented multi moduling using namespaces within controllers, models and libraries. Now most of the app has been straighten out again except for the social plugins as we were using external libraries. We had to include namespace in each and every class in those libraries. I wanted to ask, if there is any method we could use to get rid of trouble caused by using namespaces in each class in those libraries?



33.6k
Accepted
answer

You can create a service in the DI to acess these social plugins:

use MyLibrary\To\Facebook;

$di->set("fb", function() {
  // initialize your fb
  $fb = new Facebook;
  return $fb;
});

Then in the controller

public function someAction()
{
    $this->fb->something();
}

Andres, great reply, worked like a charm but google API is still not working. Probably the reason is that Google is extending way too much classes. Anyhow, 3 out of 4 APIs worked so its a job well done. Cheers.

You can create a service in the DI to acess these social plugins:

```php use MyLibrary\To\Facebook;

$di->set("fb", function() { // initialize your fb $fb = new Facebook; return $fb; }); ```

Then in the controller

```php public function someAction() { $this->fb->something(); } ```

I am keeping this thread open, in case someone else wants to step in.