Philll_t
Philll_t

Reputation: 4437

Mixing Named params with standard params Phalcon

I have a url that loads fonts as such:

/templatename/fonts/helvetica?weights=regular,bold,light

in php it will dynamically generate a CSS file with the appropriate font referencing.

We just recently moved over to to Phalcon and it broke. I'm trying to figure out how to tell the router to use the the font name as a named param but also use the standard param style. with the question marks.

this is what my router looks like right now:

...
    "fonts"=>[
             "pattern" => "/fonts/{file:[\w\W]}",
             "route" => [
                 "controller" => "asset",
                 "action" => "fonts"
              ]
       ]
...

When I use the dispatcher loop, like this:

$params = $this->dispatcher->getParams()

The array does not show the weights param:

Array
(
    [template] => templatename
    [file] => helvetica
)

How can I get it to look like this without changing the URL structure?

Array
(
    [template] => templatename
    [file] => helvetica
    [weights] => regular,bold,light
)

Upvotes: 0

Views: 73

Answers (1)

Timothy
Timothy

Reputation: 2003

If you have the following URL:

/templatename/fonts/helvetica?weights=regular,bold,light

Then weights=regular,bold,light are the GET parameters.

You can request these inside Phalcon by using:

$weights = $this->request->getQuery('weights')

You do not have to declare this inside your routes, Phalcon automatically appends these GET parameters to the end of your routes.

Check the Phalcon HTTP Request docs for more info

Upvotes: 2

Related Questions