本文整理汇总了PHP中Router::prefixes方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::prefixes方法的具体用法?PHP Router::prefixes怎么用?PHP Router::prefixes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::prefixes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
function render($url = null)
{
if ($url === null) {
$prefixes = array_flip(Router::prefixes());
array_walk($prefixes, create_function('&$item', '$item = false;'));
$url = array('plugin' => 'kcaptcha', 'controller' => 'captcha', 'action' => 'render_captcha') + $prefixes;
}
return sprintf('<img src="%s" />', $this->url($url));
}
示例2: getPrefixes
public static function getPrefixes($current = null)
{
$prefixes = Router::prefixes();
$tmp = array();
// Negative all prefixes, except the current
foreach ($prefixes as $prefix) {
$tmp[$prefix] = $prefix == $current ? true : false;
}
return $tmp;
}
示例3: _setPrefixMappings
/**
* sets the crud mappings for prefix routes.
*
* @return void
*/
protected function _setPrefixMappings()
{
$crud = array('create', 'read', 'update', 'delete');
$map = array_combine($crud, $crud);
$prefixes = Router::prefixes();
if (!empty($prefixes)) {
foreach ($prefixes as $prefix) {
$map = array_merge($map, array($prefix . '_index' => 'read', $prefix . '_add' => 'create', $prefix . '_edit' => 'update', $prefix . '_view' => 'read', $prefix . '_remove' => 'delete', $prefix . '_create' => 'create', $prefix . '_read' => 'read', $prefix . '_update' => 'update', $prefix . '_delete' => 'delete'));
}
}
$this->mapActions($map);
}
示例4: _setPrefixMappings
/**
* sets the crud mappings for prefix routes.
*
* @return void
*/
protected function _setPrefixMappings()
{
if (!Configure::read('Access Control.rowLevel')) {
return;
}
$crud = array('create', 'read', 'update', 'delete');
$map = array_combine($crud, $crud);
$Controller = $this->Controller();
if ($Controller->Components->attached('RowLevelAcl')) {
$settings = $Controller->Components->RowLevelAcl->settings;
if (isset($settings['actionMap'])) {
$map = array_merge($map, $settings['actionMap']);
}
}
$prefixes = Router::prefixes();
if (!empty($prefixes)) {
foreach ($prefixes as $prefix) {
$map = array_merge($map, array($prefix . '_moveup' => 'update', $prefix . '_movedown' => 'update', $prefix . '_process' => 'delete', $prefix . '_index' => 'read', $prefix . '_add' => 'create', $prefix . '_edit' => 'update', $prefix . '_view' => 'read', $prefix . '_remove' => 'delete', $prefix . '_create' => 'create', $prefix . '_read' => 'read', $prefix . '_update' => 'update', $prefix . '_delete' => 'delete'));
}
}
$this->mapActions($map);
}
示例5: _isActive
/**
* _isActive
*
* Determine if the current link should have the class active
*
* @param mixed $item
* @return bool
*/
protected function _isActive($item)
{
if (is_callable($this->_activeMode)) {
$callback = $this->_activeMode;
return $callback($this->_View, $item);
}
if ($this->_activeMode === 'exact') {
$url = Router::normalize($item['url']);
return $this->_here['url'] === $url;
}
$url = $item['url'];
if (is_string($url)) {
$url = Router::parse($url);
if (!$url) {
return false;
}
}
$url += array('prefix' => isset($this->request->params['prefix']) ? $this->request->params['prefix'] : null, 'plugin' => $this->request->params['plugin'], 'controller' => $this->request->params['controller'], 'action' => $this->request->params['action']);
$keys = array('plugin', 'controller', 'action');
$keys = array_slice($keys, 0, array_search($this->_activeMode, $keys) + 1);
$keys = array_merge($keys, Router::prefixes());
$keys = array_flip($keys);
$here = array_filter(array_intersect_key($this->_here['params'], $keys));
$link = array_filter(array_intersect_key($url, $keys));
ksort($here);
ksort($link);
return $link === $here;
}
示例6: _getRoute
/**
* Get the dynamic build path for an asset.
*/
protected function _getRoute($file)
{
$url = $this->options['buildUrl'];
//escape out of prefixes.
$prefixes = Router::prefixes();
foreach ($prefixes as $prefix) {
if (!array_key_exists($prefix, $url)) {
$url[$prefix] = false;
}
}
$params = array($file, 'base' => false);
$ext = $this->_Config->getExt($file);
if (isset($this->_runtime[$ext][$file])) {
$hash = $this->_getHashName($file, $ext);
$components = $this->_Config->files($file);
if ($hash) {
$params[0] = $hash;
}
$params['?'] = array('file' => $components);
}
if ($this->_Config->isThemed($file)) {
$params['?']['theme'] = $this->theme;
}
$url = Router::url(array_merge($url, $params));
return $url;
}
示例7: explainLink
/**
* Generates a SQL explain link for a given query
*
* @param string $sql SQL query string you want an explain link for.
* @return string Rendered Html link or '' if the query is not a select/describe
*/
function explainLink($sql, $connection)
{
if (!preg_match('/^(SELECT)/i', $sql)) {
return '';
}
App::import('Core', 'Security');
$hash = Security::hash($sql . $connection, null, true);
$url = array('plugin' => 'debug_kit', 'controller' => 'toolbar_access', 'action' => 'sql_explain', 'ds' => $connection, 'sql' => $sql, 'hash' => $hash);
foreach (Router::prefixes() as $prefix) {
$url[$prefix] = false;
}
return $this->Html->link(__d('debug_kit', 'Explain', true), $url, array('class' => 'sql-explain-link'));
}
示例8: foreach
* - `/:prefix/:controller/:action/*`
*
* If plugins are found in your application the following routes are created:
*
* - `/:plugin` a plugin shortcut route.
* - `/:plugin/:controller`
* - `/:plugin/:controller/:action/*`
*
* And lastly the following catch-all routes are connected.
*
* - `/:controller'
* - `/:controller/:action/*'
*
* You can disable the connection of default routes by deleting the require inside APP/Config/routes.php.
*/
$prefixes = Router::prefixes();
if ($plugins = CakePlugin::loaded()) {
App::uses('PluginShortRoute', 'Routing/Route');
foreach ($plugins as $key => $value) {
$plugins[$key] = Inflector::underscore($value);
}
$pluginPattern = implode('|', $plugins);
$match = array('plugin' => $pluginPattern, 'defaultRoute' => true);
$shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern, 'defaultRoute' => true);
foreach ($prefixes as $prefix) {
$params = array('prefix' => $prefix, $prefix => true);
$indexParams = $params + array('action' => 'index');
Router::connect("/{$prefix}/:plugin", $indexParams, $shortParams);
Router::connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
Router::connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
}
示例9: dispatch
/**
* Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the
* results (if autoRender is set).
*
* If no controller of given name can be found, invoke() shows error messages in
* the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called
* Actions).
*
* @param string $url URL information to work on
* @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
* @return boolean Success
* @access public
*/
function dispatch($url = null, $additionalParams = array())
{
if ($this->base === false) {
$this->base = $this->baseUrl();
}
if (is_array($url)) {
$url = $this->__extractParams($url, $additionalParams);
} else {
if ($url) {
$_GET['url'] = $url;
}
$url = $this->getUrl();
$this->params = array_merge($this->parseParams($url), $additionalParams);
}
$this->here = $this->base . '/' . $url;
/* xplico: we disable cache to avoid proxy error
if ($this->asset($url) || $this->cached($url)) {
return;
}
*/
/* xplico step 1: proxy implementation */
$bheader = $_SERVER['HTTP_HOST'];
if (empty($this->params['controller']) || $this->params['controller'] == 'http:' || stripos($bheader, $_SERVER['SERVER_ADDR']) === false && stripos($bheader, 'localhost') === false && stripos($bheader, 'demo.xplico.org') === false) {
if (strstr($_SERVER['REQUEST_URI'], '/webs/hijacking/') !== false) {
$this->params['controller'] = 'webs';
$this->params['action'] = 'hijacking';
} else {
$this->params['controller'] = 'webs';
$this->params['action'] = 'view';
}
}
/* end xplico step 1 */
$controller =& $this->__getController();
/* xplico step 2 */
if (!is_object($controller)) {
$this->params['controller'] = 'webs';
$this->params['action'] = 'view';
$controller =& $this->__getController();
}
/* xplico: end */
if (!is_object($controller)) {
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
return $this->cakeError('missingController', array(array('className' => Inflector::camelize($this->params['controller']) . 'Controller', 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base)));
}
$privateAction = $this->params['action'][0] === '_';
$prefixes = Router::prefixes();
if (!empty($prefixes)) {
if (isset($this->params['prefix'])) {
$this->params['action'] = $this->params['prefix'] . '_' . $this->params['action'];
} elseif (strpos($this->params['action'], '_') > 0) {
list($prefix, $action) = explode('_', $this->params['action']);
$privateAction = in_array($prefix, $prefixes);
}
}
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)));
if ($privateAction) {
return $this->cakeError('privateAction', array(array('className' => Inflector::camelize($this->params['controller'] . "Controller"), 'action' => $this->params['action'], 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base)));
}
$controller->base = $this->base;
$controller->here = $this->here;
$controller->webroot = $this->webroot;
$controller->plugin = isset($this->params['plugin']) ? $this->params['plugin'] : null;
$controller->params =& $this->params;
$controller->action =& $this->params['action'];
$controller->passedArgs = array_merge($this->params['pass'], $this->params['named']);
if (!empty($this->params['data'])) {
$controller->data =& $this->params['data'];
} else {
$controller->data = null;
}
if (isset($this->params['return']) && $this->params['return'] == 1) {
$controller->autoRender = false;
}
if (!empty($this->params['bare'])) {
$controller->autoLayout = false;
}
return $this->_invoke($controller, $this->params);
}
示例10: explainLink
/**
* Generates a SQL explain link for a given query
*
* @param string $sql SQL query string you want an explain link for.
* @return string Rendered Html link or '' if the query is not a select/describe
*/
function explainLink($sql, $connection)
{
if (!preg_match('/^(SELECT)/i', $sql)) {
return '';
}
App::import('Core', 'Security');
$hash = Security::hash($sql . $connection, null, true);
$url = array('plugin' => 'debug_kit', 'controller' => 'toolbar_access', 'action' => 'sql_explain');
foreach (Router::prefixes() as $prefix) {
$url[$prefix] = false;
}
$form = $this->Form->create('log', array('url' => $url));
$form .= $this->Form->hidden('log.ds', array('value' => $connection));
$form .= $this->Form->hidden('log.sql', array('value' => $sql));
$form .= $this->Form->hidden('log.hash', array('value' => $hash));
$form .= $this->Form->submit(__d('debug_kit', 'Explain', true), array('div' => false, 'class' => 'sql-explain-link'));
$form .= $this->Form->end();
return $form;
}
示例11: initialize
/**
* Initializes AuthComponent for use in the controller
*
* @param object $controller A reference to the instantiating controller object
* @return void
* @access public
*/
function initialize(&$controller, $settings = array())
{
$this->controller =& $controller;
$this->params = $controller->params;
$crud = array('create', 'read', 'update', 'delete');
$this->_set($settings);
$this->actionMap = array_merge(array_combine($crud, $crud), $this->actionMap);
$this->_methods = $controller->methods;
$prefixes = Router::prefixes();
if (!empty($prefixes)) {
foreach ($prefixes as $prefix) {
$this->actionMap = array_merge(array($prefix . '_index' => 'read', $prefix . '_add' => 'create', $prefix . '_edit' => 'update', $prefix . '_view' => 'read', $prefix . '_remove' => 'delete', $prefix . '_create' => 'create', $prefix . '_read' => 'read', $prefix . '_update' => 'update', $prefix . '_delete' => 'delete'), $this->actionMap);
}
}
if (Configure::read() > 0) {
App::import('Debugger');
Debugger::checkSecurityKeys();
}
}
示例12: match
/**
* Attempt to match a url array. If the url matches the route parameters and settings, then
* return a generated string url. If the url doesn't match the route parameters, false will be returned.
* This method handles the reverse routing or conversion of url arrays into string urls.
*
* @param array $url An array of parameters to check matching with.
* @return mixed Either a string url for the parameters if they match or false.
*/
public function match($url) {
if (!$this->compiled()) {
$this->compile();
}
$defaults = $this->defaults;
if (isset($defaults['prefix'])) {
$url['prefix'] = $defaults['prefix'];
}
//check that all the key names are in the url
$keyNames = array_flip($this->keys);
if (array_intersect_key($keyNames, $url) !== $keyNames) {
return false;
}
// Missing defaults is a fail.
if (array_diff_key($defaults, $url) !== array()) {
return false;
}
$namedConfig = Router::namedConfig();
$prefixes = Router::prefixes();
$greedyNamed = $namedConfig['greedyNamed'];
$allowedNamedParams = $namedConfig['rules'];
$named = $pass = array();
foreach ($url as $key => $value) {
// keys that exist in the defaults and have different values is a match failure.
$defaultExists = array_key_exists($key, $defaults);
if ($defaultExists && $defaults[$key] != $value) {
return false;
} elseif ($defaultExists) {
continue;
}
// If the key is a routed key, its not different yet.
if (array_key_exists($key, $keyNames)) {
continue;
}
// pull out passed args
$numeric = is_numeric($key);
if ($numeric && isset($defaults[$key]) && $defaults[$key] == $value) {
continue;
} elseif ($numeric) {
$pass[] = $value;
unset($url[$key]);
continue;
}
// pull out named params if named params are greedy or a rule exists.
if (
($greedyNamed || isset($allowedNamedParams[$key])) &&
($value !== false && $value !== null) &&
(!in_array($key, $prefixes))
) {
$named[$key] = $value;
continue;
}
// keys that don't exist are different.
if (!$defaultExists && !empty($value)) {
return false;
}
}
//if a not a greedy route, no extra params are allowed.
if (!$this->_greedy && (!empty($pass) || !empty($named))) {
return false;
}
//check patterns for routed params
if (!empty($this->options)) {
foreach ($this->options as $key => $pattern) {
if (array_key_exists($key, $url) && !preg_match('#^' . $pattern . '$#', $url[$key])) {
return false;
}
}
}
return $this->_writeUrl(array_merge($url, compact('pass', 'named')));
}
示例13: testPassedArgsOrder
/**
* testPassedArgsOrder method
*
* @return void
*/
public function testPassedArgsOrder()
{
Router::connect('/test-passed/*', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1));
Router::parse('/');
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 1, 'whatever'));
$expected = '/test/whatever';
$this->assertEquals($expected, $result);
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 2, 'whatever'));
$expected = '/test2/whatever';
$this->assertEquals($expected, $result);
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 'home', 'whatever'));
$expected = '/test-passed/whatever';
$this->assertEquals($expected, $result);
Configure::write('Routing.prefixes', array('admin'));
Router::reload();
$request = new CakeRequest();
Router::setRequestInfo($request->addParams(array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'url' => array('url' => 'protected/images/index')))->addPaths(array('base' => '', 'here' => '/protected/images/index', 'webroot' => '/')));
Router::connect('/protected/:controller/:action/*', array('controller' => 'users', 'action' => 'index', 'prefix' => 'protected'));
Router::parse('/');
$result = Router::url(array('controller' => 'images', 'action' => 'add'));
$expected = '/protected/images/add';
$this->assertEquals($expected, $result);
$result = Router::prefixes();
$expected = array('admin', 'protected');
$this->assertEquals($expected, $result);
}
示例14: dispatch
/**
* Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the results (if autoRender is set).
*
* If no controller of given name can be found, invoke() shows error messages in
* the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called
* Actions).
*
* @param string $url URL information to work on
* @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
* @return boolean Success
* @access public
*/
function dispatch($url = null, $additionalParams = array())
{
$parse = true;
if ($this->base === false) {
$this->base = $this->baseUrl();
}
if (is_array($url)) {
$url = $this->__extractParams($url, $additionalParams);
$parse = false;
}
if ($url !== null) {
$_GET['url'] = $url;
}
if ($parse) {
$url = $this->getUrl();
}
$this->here = $this->base . '/' . $url;
if ($this->cached($url)) {
$this->_stop();
}
if ($parse) {
$this->params = array_merge($this->parseParams($url), $additionalParams);
}
$controller = $this->__getController();
if (!is_object($controller)) {
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
return $this->cakeError('missingController', array(array('className' => Inflector::camelize($this->params['controller']) . 'Controller', 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base)));
}
$missingAction = $missingView = $privateAction = false;
if (empty($this->params['action'])) {
$this->params['action'] = 'index';
}
$prefixes = Router::prefixes();
if (!empty($prefixes)) {
if (isset($this->params['prefix'])) {
$this->params['action'] = $this->params['prefix'] . '_' . $this->params['action'];
} elseif (strpos($this->params['action'], '_') !== false) {
list($prefix, $action) = explode('_', $this->params['action']);
$privateAction = in_array($prefix, $prefixes);
}
}
$protected = array_map('strtolower', get_class_methods('controller'));
$classMethods = array_map('strtolower', get_class_methods($controller));
if (in_array(strtolower($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) {
$privateAction = true;
}
if (!in_array(strtolower($this->params['action']), $classMethods)) {
$missingAction = true;
}
if (in_array('return', array_keys($this->params)) && $this->params['return'] == 1) {
$controller->autoRender = false;
}
$controller->base = $this->base;
$controller->here = $this->here;
$controller->webroot = $this->webroot;
$controller->plugin = $this->plugin;
$controller->params =& $this->params;
$controller->action =& $this->params['action'];
$controller->passedArgs = array_merge($this->params['pass'], $this->params['named']);
if (!empty($this->params['data'])) {
$controller->data =& $this->params['data'];
} else {
$controller->data = null;
}
if (!empty($this->params['bare'])) {
$controller->autoLayout = false;
}
if (isset($this->params['layout'])) {
if ($this->params['layout'] === '') {
$controller->autoLayout = false;
} else {
$controller->layout = $this->params['layout'];
}
}
if (isset($this->params['viewPath'])) {
$controller->viewPath = $this->params['viewPath'];
}
foreach (array('components', 'helpers') as $var) {
if (isset($this->params[$var]) && !empty($this->params[$var]) && is_array($controller->{$var})) {
$diff = array_diff($this->params[$var], $controller->{$var});
$controller->{$var} = array_merge($controller->{$var}, $diff);
}
}
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)));
$controller->constructClasses();
if ($privateAction) {
return $this->cakeError('privateAction', array(array('className' => Inflector::camelize($this->params['controller'] . "Controller"), 'action' => $this->params['action'], 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base)));
}
//.........这里部分代码省略.........
示例15: _generateAsset
/**
* Generates the asset tag of the chosen $method
*
* @param string $method Method name to call on HtmlHelper
* @param string $destination The destination file to be generated.
* @param array $url Array of url keys for making the asset location.
* @return string Asset tag.
*/
protected function _generateAsset($method, $destination, $files, $url)
{
$fileString = 'file[]=' . implode('&file[]=', $files);
$iniKey = $method == '_css' ? 'Css' : 'Javascript';
if (!empty($this->_iniFile[$iniKey]['timestamp']) && Configure::read('debug') < 2) {
$destination = $this->_timestampFile($destination);
}
//escape out of prefixes.
$prefixes = Router::prefixes();
foreach ($prefixes as $prefix) {
if (!array_key_exists($prefix, $url)) {
$url[$prefix] = false;
}
}
$url = Router::url(array_merge($url, array($destination, '?' => $fileString, 'base' => false)));
list($base, $query) = explode('?', $url);
if (file_exists(WWW_ROOT . $base)) {
$url = $base;
}
if ($method == '_css') {
return $this->Html->css($url);
} else {
return $this->Html->script($url);
}
}