V
V
Vyacheslav Saratovsky2016-03-31 13:07:05
PHP
Vyacheslav Saratovsky, 2016-03-31 13:07:05

How to put a provider controller inside a provider controller?

There is a provider class SystemControllerProvider, in which another controller provider AdminGroupsControllerProvider should be connected.
In this example, the white page response code is 200, and the rest of the routes do not work either

class SystemControllerProvider implements ControllerProviderInterface
{
    public function connect(Application $app)
    {
        $controllers = $app['controllers_factory'];

        $controllers->mount('/groups', new AdminGroupsControllerProvider());

        return $controllers;
    }
}

class AdminGroupsControllerProvider implements ControllerProviderInterface {

  public function connect(Application $app) {

        $controllers = $app['controllers_factory'];

        $controllers->get('/', "Controllers\AdminGroupsControllerProvider::getGroups");

        return $controllers;
    }

public function getGroups(Request $request, Application $app){

    $data = [
      "name" => 'Тест',
      "perm" => [1,2,3,4,5,6],
      "addedby" =>$app['session']->get('uid')	
    ];

    $responseStatus = 200;

    $response = new JsonResponse();
                $response->headers->set('Content-Type', 'application/json');
               $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
               $response->setStatusCode(200);
               $response->setData($data);
               return $response;
  }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question