There is a URL: http: // localhost / page / example / edit / 123 actually, how to get the string values ​​correctly: page / example / edit / 123 First thing that comes to mind: $variables = explode('/', $this->request->get('_url')); but in my opinion to address through the keys is not very convenient ...

Tried through routing, but the variables that I specify there can not get. Example: index.php:

 $router->add("/([az])/([az])/([az])/([0-9])", array( "controller" => "myController", "action" => "my", "var1" => 3, "var2" => 4, ) ); $router->handle(); 

Well, the controller code: myController.php:

 public function myAction() { echo 'Зачение: '.$this->dispatcher->getParam("var1"); $this->view->disable(); } 

As a result, displays:

Zacheniye:

although I need to display: Meaning: edit Actually, how to be? How easier is it to parse the URL

  • Maybe you should replace the regular "/ ([az]) / ([az]) / ([az]) / ([0-9])" with the correct "/ ([az] +) / ([az] +) / ([az] +) / ([0-9] +) ";) - Visman am

1 answer 1

First, in Phalcon, how to properly parse the URL? correctly stated - the regulars must be changed.

Secondly, I advise you to use named parameters:

 $router->add("/[az]+/[az]+/{var1:[az]+}/{var2:[0-9]+}", array( "controller" => "myController", "action" => "my", ) 

);