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

How to get parameters from the URL with Phalcon\Mvc\Micro\Collection

I use Phalcon\Mvc\Micro\Collection to set up routing .here is my code:

<?php
    use Phalcon\Mvc\Micro\Collection;

    return call_user_func(function () {
        $rules['grade']     = new Collection();
        $rules['grade']->setHandler('\Api\Grade')->setPrefix('/api/v1/user/{uuid:[a-zA-Z0-9]+}/grades')->setLazy(true);
        $rules['grade']->post('/{classId:[0-9]+}/apply', 'apply');
        return $rules;
    }
?>

https://localhost:8080/api/v1/user/0cafdf577605/grades/1/apply

<?php
    namespace Api\Grade;
    var_dump($this->request->getQuery());//result: array(1) { ["_url"]=> string(40) "/api/v1/user/0cafdf577605/grades/1/apply" }
    var_dump($this->request->get());//result: array(1) { ["_url"]=> string(40) "/api/v1/user/0cafdf577605/grades/1/apply" }
    var_dump($this->request->getPost());//result: array(0) { }
?>

I want to get the value of the classId .What should I do?

edited May '17

In handler method/function just add $uuid and $classId as parameters/arguments.

Not sure if parameter in prefix will work. You can possibly access them using $this->router->getParams(). But better just add them as argument to function/method.