Hello. I study the work of the urlmanager in yii2 and I can not figure out parseReequest, I created my own class

public function createUrl($manager, $route, $params) { if ($route === 'template/view') { if (isset($params['id'])) { $template = Template::findOne($params['id']); if (!empty($template)) { $slug = $template->slug; return 'template/'.$slug.'/view'; } } } elseif ($route === 'template/update') { if (isset($params['id'])) { $template = Template::findOne($params['id']); if (!empty($template)) { $slug = $template->slug; return 'template/'.$slug.'/update'; } } } } public function parseRequest ($manager, $request) { $pathInfo = $request->getPathInfo(); if (preg_match('%^template/(\w+)(?:/(\w+))$%', $pathInfo, $matches)) { $template = Template::findOne($params['id']); if (!empty($template)) { $params['id'] = $template->id; return ['template/' . $matches[1], $params]; } } return false; } 

I can not understand how to parse, that would automatically substitute action! how to do it right?

  • template do you have a module or controller? - Blacknife
  • @Blacknife template - controller - Roman
  • And to what action of the controller does this route belong? : 'template/'.$slug.'/update' - Blacknife
  • @Blacknife // so first I collect the link that would not be template/view?id=480 or template/update?id=480 but received a view like template/slug/view or template/slug/update are normal, the links are converted, and Here's how to parse and send I can not figure it out. parseRequest does not give in to me ((((.. - Roman
  • so lay out the code of the second method, as you tried? - Blacknife

0