本文整理匯總了PHP中route::setVars方法的典型用法代碼示例。如果您正苦於以下問題:PHP route::setVars方法的具體用法?PHP route::setVars怎麽用?PHP route::setVars使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類route
的用法示例。
在下文中一共展示了route::setVars方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAllRoutes
/**
* get all routes
* get the URLs, the variables, the modules and the actions of all routes, use the "/applications/config/routes.xml" file.
* @param string current url (optionnal)
* @return array list of routes object
*/
public function getAllRoutes($currentUrl = null)
{
//get content of the file.
$xml = new \DOMDocument();
$xml->load(__DIR__ . '/../applications/config/routes.xml');
$file = $xml->getElementsByTagName('route');
//parse the content.
$varsNames = array();
$varsValues = array();
$varsList = array();
foreach ($file as $line) {
//create the route.
$varsNames = explode(',', $line->getAttribute('vars'));
//get the name of all variables
$route = new route($line->getAttribute('url'), $line->getAttribute('module'), $line->getAttribute('action'), $line->getAttribute('name'), $varsNames);
//get variables.
if ($varsValues = $route->match($currentUrl)) {
array_shift($varsValues);
// the first result contain the full captured string (cf. pregmatch manual).
foreach ($varsValues as $key => $match) {
$varsList[$varsNames[$key]] = $match;
}
$route->setVars($varsList);
}
//add the route to the router.
$this->addRoute($route);
}
//return all routes.
return $this->routes;
}