Example #1
0
 function renderView($action)
 {
     foreach ($this->vars as $k => $val) {
         ${$k} = $val;
     }
     if (strpos($this->views_dir, DS) !== false) {
         $viewpath = $this->views_dir;
     } else {
         $viewpath = self::getViewsPath($this->controller, $this->views_dir);
         $viewpath = \GCore\C::fix_path($viewpath);
     }
     $action_file = '';
     if (is_string($this->view)) {
         if (strpos($this->view, DS) !== false) {
             $action_file = $this->view;
         } else {
             $action = $this->view;
         }
     }
     $action_file = empty($action_file) ? $viewpath . $action . '.php' : $action_file;
     if ($this->view !== false and file_exists($action_file)) {
         //view file exists, load it
         ob_start();
         include $action_file;
         $contents = ob_get_clean();
         if (!empty($this->data)) {
             $contents = Str::replacer($contents, Request::raw(), array('escape' => true));
             $contents = \GCore\Helpers\DataLoader::load($contents, Request::raw());
         }
         echo $contents;
     }
 }
Example #2
0
 public static function register($name)
 {
     if (empty(self::$start_time)) {
         self::$start_time = microtime(true);
         self::$memory_usage = memory_get_usage();
     }
     if (strlen(trim($name)) > 0) {
         $dirs = explode("\\", $name);
         $dirs = array_values(array_filter($dirs));
         //if the class doesn't belong to the GCore then don't try to auto load it
         if ($dirs[0] !== "GCore") {
             return false;
         }
         //build the include file path
         $strings = array();
         foreach ($dirs as $k => $dir) {
             if ($dir === "GCore") {
                 //root dir
                 $strings[] = dirname(__FILE__);
                 continue;
             }
             if ($k == count($dirs) - 1) {
                 //last dir (file name)
                 $strings[] = strtolower(preg_replace('/([a-z]|[0-9])([A-Z])/', '$1_$2', $dir)) . ".php";
                 continue;
             }
             if (empty($dirs[$k])) {
                 //empty value
                 continue;
             }
             //otherwise, uncamilize the namespace name to get the directory name
             $strings[] = strtolower(preg_replace('/([a-z]|[0-9])([A-Z])/', '$1_$2', $dir));
         }
         //load the file if exists
         $file = implode(DIRECTORY_SEPARATOR, $strings);
         //self::$filepath = $file;
         //$gcore_file = $file;
         //$file = str_replace('__GCORE__', dirname(__FILE__), $gcore_file);
         $file = \GCore\C::fix_path($file);
         //pr($file);
         if (file_exists($file) and substr($file, -4, 4) == ".php") {
             require_once $file;
             if (class_exists($name)) {
                 return true;
             } else {
                 self::$filepath = $file;
                 self::$classname = $name;
             }
         }
         /*if(Libs\Base::getConfig('debug', 0)){
         			self::debug();
         		}*/
     }
 }