Esempio n. 1
0
 /**
  *  Render a view. This method instead of Load::view() prefixes paths with current module directory.
  */
 public static function render($views, $data = [])
 {
     $views = (array) $views;
     foreach ($views as $key => $item) {
         $views[$key] = Router::$module . DS . 'Views' . DS . $item;
     }
     Load::view($views, $data);
 }
Esempio n. 2
0
 /**
  * Example method for help page.
  *
  * @access public
  * @static
  * @return void
  */
 public static function help()
 {
     Load::view('Defaults/Views/help.html');
 }
Esempio n. 3
0
 /**
  * Make a query.
  *
  * Should be used for insert and update queries, but also can be used as iterator for select queries.
  *
  * @example models\Db::query('INSERT INTO posts (title) VALUES (?)', ['New post title'], 'pgsql1');
  * @example $query = models\Db::query('SELECT * FROM posts', null, 'pgsql1');<br />
  *          foreach ($query as $item)<br />
  *          {<br />
  *              // Do something with the $item<br />
  *          }
  * @access public
  * @static
  * @param  string       $query
  * @param  mixed[]      $data  (default: null)
  * @param  string       $name  (default: 'default')
  * @return PDOStatement Returns statement created by query.
  */
 public static function query($query, $data = null, $name = 'default')
 {
     $db_link =& self::$db_links[$name]['link'];
     if (empty($query)) {
         return null;
     }
     if (empty($db_link)) {
         throw new \Exception('No connection to database');
     }
     // Do request
     if (!empty(self::$db_links[$name]['config']['debug'])) {
         Load::startTimer();
     }
     self::$last_statement = $db_link->prepare($query);
     self::$last_statement->execute((array) $data);
     if (!empty(self::$db_links[$name]['config']['debug'])) {
         $log = $query;
         if (!empty($data)) {
             $log_data = array_map(function ($item) {
                 return is_integer($item) == true ? $item : "'" . $item . "'";
             }, (array) $data);
             $log = str_replace(array_pad([], substr_count($query, '?'), '?'), $log_data, $query);
         }
         Load::stopTimer($log);
     }
     // Return last statement
     return self::$last_statement;
 }
Esempio n. 4
0
 /**
  * Output an error to the browser and stop script execution.
  *
  * @access public
  * @static
  * @param  int    $error_code
  * @param  string $error_string (default: '')
  * @param  string $description  (default: '')
  * @return void
  */
 public static function error($error_code, $error_string = '', $description = '')
 {
     header('HTTP/1.0 ' . $error_code . ' ' . $error_string);
     $data = ['description' => $description];
     Load::view("Errors/E{$error_code}.html", $data);
     exit;
 }
Esempio n. 5
0
    $function = new Twig_SimpleFunction('stopTimer', function ($name) {
        Load::stopTimer($name);
    });
    Load::$config['view_engine']->addFunction($function);
    // Mark time function
    $function = new Twig_SimpleFunction('markTime', function ($name) {
        Load::markTime($name);
    });
    Load::$config['view_engine']->addFunction($function);
    // Debug output function
    $function = new Twig_SimpleFunction('debugOutput', function () {
        return Load::debugOutput();
    });
    Load::$config['view_engine']->addFunction($function);
}
// Autoload helpers
if (!empty(Load::$config['autoload_helpers'])) {
    foreach (Load::$config['autoload_helpers'] as $item) {
        $tmp = explode('/', $item);
        $count = count($tmp);
        if ($count == 3) {
            Load::helper($tmp[2], $tmp[1], $tmp[0]);
        } elseif ($count == 2) {
            Load::helper($tmp[1], $tmp[0]);
        } else {
            Load::helper($tmp[0]);
        }
    }
}
// Init router
Router::init();