We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Micro Application wildcard routes

I want following urls to match one route:

/proxy/webservice1/method1/name

/proxy/webservice1/method2/param1/param2

/proxy/webservice2/method1/param1/param2/param3

So I defined route as follow :

# Webservice proxy Controller
$proxy = new MicroCollection();
$proxy->setHandler('ProxyController', true);
$proxy->setPrefix('/proxy');
$proxy->get('/{webservice}/:params', 'getAction');
$app->mount($proxy);

And controller :

class ProxyController extends Phalcon\Mvc\Controller
{

  public function getAction($webservice){

    var_dump($webservice);
    $params = $this->dispatcher->getParams();
    var_dump($params);
  }
}
?>

I do have the $webservice but how can I access the others? $params is always empty.

Thanks for your comments.

Is $this->getDI()->getParams() work?



714

Nop. When I call

$this->getDI();

I get an object Phalcon\Di\FactoryDefault and there is no getParams function.

Are you accessing the routes like: /proxy/something/x/y/z ?



714

Yes exactly.

I have the same problem, is there already a solution?



714
Accepted
answer
edited Nov '15

I found a way to access the requested url via Phalcon\Http\Request

class ProxyController extends Phalcon\Mvc\Controller
{

  public function getAction($webservice){

    # Get request
    $request = new Phalcon\Http\Request();
    $query   = $request->getQuery();

    #  Get path
    $path = $query['_url'];
  }
}

With this object you can access the requested path, Post, Get or raw body of the request

# Check method
$request->isGet()

# Post fields
$post = $request->getPost();

# Request body
$raw = $request->getRawBody();