本文整理汇总了PHP中JInput::def方法的典型用法代码示例。如果您正苦于以下问题:PHP JInput::def方法的具体用法?PHP JInput::def怎么用?PHP JInput::def使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JInput
的用法示例。
在下文中一共展示了JInput::def方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDef
/**
* Test the JInput::def method.
*
* @return void
*
* @since 12.1
*/
public function testDef()
{
$_REQUEST['foo'] = 'bar';
$this->class->def('foo', 'nope');
$this->assertThat($_REQUEST['foo'], $this->equalTo('bar'), 'Line: ' . __LINE__ . '.');
$this->class->def('Joomla', 'is great');
$this->assertThat($_REQUEST['Joomla'], $this->equalTo('is great'), 'Line: ' . __LINE__ . '.');
}
示例2: parseRoute
/**
* Parse the given route and return the name of a controller mapped to the given route.
*
* @param string $route The route string for which to find and execute a controller.
*
* @return string The controller name for the given route excluding prefix.
*
* @since 1.0
* @throws \InvalidArgumentException
*/
protected function parseRoute($route)
{
$controller = false;
// Trim the query string off.
$route = preg_replace('/([^?]*).*/u', '\\1', $route);
// Sanitize and explode the route.
$route = trim(static::parseUrl($route, PHP_URL_PATH), ' /');
// If the route is empty then simply return the default route. No parsing necessary.
if ($route == '') {
return $this->default;
}
// Iterate through all of the known route maps looking for a match.
foreach ($this->maps as $key => $rule) {
if (preg_match($rule['regex'], $route, $matches)) {
// If we have gotten this far then we have a positive match.
$controller = $rule['controller'];
// Time to set the input variables.
// We are only going to set them if they don't already exist to avoid overwriting things.
foreach ($rule['vars'] as $i => $var) {
$this->input->def($var, $matches[$i + 1]);
// Don't forget to do an explicit set on the GET superglobal.
$this->input->get->def($var, $matches[$i + 1]);
}
$this->input->def('_rawRoute', $route);
$name = $key;
break;
}
}
// We were unable to find a route match for the request. Panic.
if (!$controller) {
throw new \InvalidArgumentException(sprintf('Unable to handle request for route `%s`.', $route), 404);
}
if (is_callable($this->parseHandler[$name])) {
call_user_func_array($this->parseHandler[$name], array($controller, $this->input));
}
return $controller;
}