Added better support for hyphens in a URI.
This commit is contained in:
parent
346c93e393
commit
261b2546e7
2 changed files with 28 additions and 12 deletions
|
@ -108,7 +108,7 @@ class Controller extends Object
|
|||
$request[key($request)] = $last_part;
|
||||
}
|
||||
|
||||
list($basename, $module_class, $module_filename, $template_basename, $css_class, $js_basename) = $this->prepareVariables(implode('/', $request));
|
||||
list($module_class, $module_filename, $template_basename, $css_class, $js_basename) = $this->prepareVariables(implode('/', $request));
|
||||
|
||||
unset($last_part, $request);
|
||||
}
|
||||
|
@ -117,11 +117,9 @@ class Controller extends Object
|
|||
{
|
||||
$default_module = isset($this->config->pickles['module']) ? $this->config->pickles['module'] : 'home';
|
||||
|
||||
list($basename, $module_class, $module_filename, $template_basename, $css_class, $js_basename) = $this->prepareVariables($default_module);
|
||||
list($module_class, $module_filename, $template_basename, $css_class, $js_basename) = $this->prepareVariables($default_module);
|
||||
}
|
||||
|
||||
unset($basename);
|
||||
|
||||
$module_exists = (isset($module_filename) && $module_filename != null && file_exists($module_filename));
|
||||
|
||||
// Instantiates an instance of the module
|
||||
|
@ -265,7 +263,6 @@ class Controller extends Object
|
|||
|
||||
// Redirect to login page, potentially configured in the config, else /login
|
||||
header('Location: /' . (isset($this->config->security['login']) ? $this->config->security['login'] : 'login'));
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
@ -458,19 +455,25 @@ class Controller extends Object
|
|||
* Processes the request variable and creates all the variables that the
|
||||
* Controller needs to load the page.
|
||||
*
|
||||
* @param string $request the requested page
|
||||
* @param string $basename the requested page
|
||||
* @return array the resulting variables
|
||||
*/
|
||||
public function prepareVariables($request)
|
||||
public function prepareVariables($basename)
|
||||
{
|
||||
$basename = strtr($request, '-', '_');
|
||||
// Sets up all of our variables
|
||||
$module_class = strtr($basename, '/', '_');
|
||||
$module_filename = SITE_MODULE_PATH . $basename . '.php';
|
||||
$template_basename = $basename;
|
||||
$css_class = str_replace(array('_', '/', ' '), '-', $basename);
|
||||
$css_class = $module_class;
|
||||
$js_basename = $basename;
|
||||
|
||||
return array($basename, $module_class, $module_filename, $template_basename, $css_class, $js_basename);
|
||||
// Scrubs class names with hyphens
|
||||
if (strpos($module_class, '-') !== false)
|
||||
{
|
||||
$module_class = preg_replace('/(-(.{1}))/e', 'strtoupper("$2")', $module_class);
|
||||
}
|
||||
|
||||
return array($module_class, $module_filename, $template_basename, $css_class, $js_basename);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
pickles.php
17
pickles.php
|
@ -131,13 +131,26 @@ function __autoload($class)
|
|||
|
||||
$filename = preg_replace('/_/', '/', $class) . '.php';
|
||||
|
||||
$paths = array(PICKLES_CLASS_PATH, SITE_CLASS_PATH, SITE_MODEL_PATH, SITE_MODULE_PATH);
|
||||
// Path as the key, boolean value is whether ot not to convert back to hyphenated
|
||||
$paths = array(
|
||||
PICKLES_CLASS_PATH => false,
|
||||
SITE_CLASS_PATH => false,
|
||||
SITE_MODEL_PATH => false,
|
||||
SITE_MODULE_PATH => true,
|
||||
);
|
||||
|
||||
foreach ($paths as $path)
|
||||
foreach ($paths as $path => $hyphenated)
|
||||
{
|
||||
// Converts the filename back to hypenated
|
||||
if ($hyphenated == true)
|
||||
{
|
||||
$filename = strtolower(preg_replace('/([A-Z]{1})/', '-$1', $filename));;
|
||||
}
|
||||
|
||||
if (file_exists($path . $filename))
|
||||
{
|
||||
$loaded = require_once $path . $filename;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue