Exemple #1
0
 function load_model($file, $args = NULL)
 {
     $class = $file . '_model';
     if (class_exists($class)) {
         return;
     }
     require_once first_glob("models/{$file}.php");
     get_controller()->{$class} = new $class($args);
 }
Exemple #2
0
function route(&$args, $default_segments)
{
    $segments = [];
    foreach (glob_segments() as $key => $array) {
        if ($key === 'class') {
            $array = array_map(function ($path) {
                return preg_replace('/\\.php$/', '', basename($path));
            }, glob_files('controllers/*.php', $segments));
        }
        if ($key === 'method') {
            if (!class_exists('controller')) {
                require_once first_glob('core/controller.php', $segments);
            }
            if (!class_exists($segments['class'])) {
                require_once first_glob("controllers/{$segments['class']}.php", $segments);
            }
            $array = get_class_methods($segments['class']);
        }
        $segments[$key] = isset($args[0]) && !preg_match('/^_/', $args[0]) && $args[0] != $default_segments[$key] && in_array($args[0], $array) ? array_shift($args) : $default_segments[$key];
    }
    return $segments;
}
Exemple #3
0
 function direct($file, $protocol = NULL, $hidden = FALSE)
 {
     return href(preg_replace('#^' . BASEPATH . '#', '', first_glob('direct/' . $file)), $protocol, $hidden);
 }