Created
April 24, 2010 07:58
-
-
Save josegonzalez/377536 to your computer and use it in GitHub Desktop.
AppHelper replacement to use named urls like @prefix_plugin_controller_action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Short description for file. | |
* | |
* This file is application-wide helper file. You can put all | |
* application-wide helper-related methods here. | |
* | |
* PHP versions 4 and 5 | |
* | |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | |
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
* | |
* Licensed under The MIT License | |
* Redistributions of files must retain the above copyright notice. | |
* | |
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
* @link http://cakephp.org CakePHP(tm) Project | |
* @package cake | |
* @subpackage cake.cake | |
* @since CakePHP(tm) v 0.2.9 | |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | |
*/ | |
App::import('Helper', 'Helper', false); | |
/** | |
* This is a placeholder class. | |
* Create the same file in app/app_helper.php | |
* | |
* Add your application-wide methods in the class below, your helpers | |
* will inherit them. | |
* | |
* @package cake | |
* @subpackage cake.cake | |
*/ | |
class AppHelper extends Helper { | |
var $plugins = null; | |
function url($url = null, $full = false) { | |
// Check to see if this is a special linked url | |
if (is_string($url) && substr($url, 0, 1) == '@') { | |
// Lets split up the url by / | |
$url_keys = explode('/', substr($url, 1)); | |
$url = array(); | |
if (in_array($url_keys['0'], Configure::read('Routing.prefixes'))) { | |
// We have a prefix | |
$url['prefix'] = array_shift($url_keys); | |
$url[$url['prefix']] = true; | |
} | |
if (in_array($url_keys['0'], $this->_pluginList())) { | |
// We have a prefix | |
$url['plugin'] = array_shift($url_keys); | |
} | |
$url['controller'] = array_shift($url_keys); | |
$url['action'] = (empty($url_keys)) ? 'index' : array_shift($url_keys); | |
foreach ($url_keys as $url_key) { | |
$url[] = $url_key; | |
} | |
} | |
return parent::url($url, $full); | |
} | |
function _pluginList() { | |
if ($this->plugins) return $this->plugins; | |
if (($this->plugins = Cache::read('helper.plugins')) == false) { | |
App::import('Core', 'File', 'Folder'); | |
$paths = Configure::getInstance(); | |
$folder =& new Folder(); | |
$folder->cd(APP . 'plugins'); | |
// Get the list of plugins | |
$Plugins = $folder->read(); | |
Cache::write('helper.plugins', $Plugins['0']); | |
$this->plugins = $Plugins['0']; | |
} | |
return $this->plugins; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment