Guest User

Untitled

a guest
Nov 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. <?php
  2.  
  3. class Controller
  4. {
  5.  
  6.     public function getUrl($name, array $data = array())
  7.     {
  8.         $route = $this->getRequest()->getRouteByName($name);
  9.         if (!$route) {
  10.             return;
  11.         }
  12.         $url = $regex = preg_replace_callback(
  13.             Route::PATTERN_REGEX,
  14.             function($matches) {
  15.                 list(, $noRef, $type, $name) = $matches;
  16.                 if (isset($data[$name])) {
  17.                     return $data[$name];
  18.                 }
  19.             },
  20.             $route->getPattern()
  21.         );
  22.         return $url;
  23.     }
  24.  
  25. }
Add Comment
Please, Sign In to add comment