Exemplo n.º 1
0
 public function render($content_view, $data = null)
 {
     if (is_array($data)) {
         extract($data);
     }
     ob_start();
     include 'application/views/' . mb_strtolower($this->controller) . '/' . $content_view . '.php';
     $content = ob_get_contents();
     ob_end_clean();
     include 'application/views/layouts/' . $this->layout . '.php';
     Mi::app()->log->draw();
 }
Exemplo n.º 2
0
 function __construct()
 {
     $path = explode('?', $_SERVER['REQUEST_URI'])[0];
     $routes = explode('/', $path);
     if (!empty($routes[1])) {
         $this->controller = ucfirst($routes[1]);
     }
     if (!empty($routes[2])) {
         $this->action = $routes[2];
     }
     $this->controller = $this->controller . 'Controller';
     $this->action = 'action' . ucfirst($this->action);
     $rules = Mi::app()->urlRules();
     if (isset($rules[$path])) {
         $routes = explode('/', $rules[$path]);
         $this->controller = ucfirst($routes[0]) . 'Controller';
         $this->action = 'action' . ucfirst($routes[1]);
     }
 }
Exemplo n.º 3
0
 public function draw()
 {
     if (!LOG) {
         return false;
     }
     $find = ['select', 'from', 'where', 'order by', 'limit', 'offset', '(', ')'];
     $replace = ['<span class="op">select</span>', '<span class="op">from</span>', '<span class="op">where</span>', '<span class="op">order by</span>', '<span class="op">limit</span>', '<span class="op">offset</span>', '<span class="op">(</span>', '<span class="op">)'];
     $querys = $this->mysql();
     $data = [];
     $i = 0;
     foreach ($querys as $query) {
         $data[$i]['sql'] = str_replace($find, $replace, strtolower($query['sql']));
         $data[$i]['time'] = $query['time'];
         $i++;
     }
     if (!isset($querys[Mi::app()->session->get('log_sql_session_id')])) {
         $data = [];
     }
     include 'views/log.php';
 }
Exemplo n.º 4
0
 public function actionIndex()
 {
     $this->pageTitle = 'Главная страница';
     $this->render('index', ['time' => Mi::app()->timeRequest, 'data' => User::model()->findByPk(1)]);
 }
Exemplo n.º 5
0
 function __construct($class_name)
 {
     $this->model = new $class_name();
     $this->db = Mi::app()->db;
 }
Exemplo n.º 6
0
 public function timeRequest()
 {
     $time = microtime(true) - Mi::app()->session->get('microtime');
     return sprintf('%.4F сек.', $time);
 }
Exemplo n.º 7
0
 private function prepareQuery($args)
 {
     $query = '';
     $raw = array_shift($args);
     $array = preg_split('~(\\?[nsiuap])~u', $raw, null, PREG_SPLIT_DELIM_CAPTURE);
     $anum = count($args);
     $pnum = floor(count($array) / 2);
     if ($pnum != $anum) {
         $this->error("Number of args ({$anum}) doesn't match number of placeholders ({$pnum}) in [{$raw}]");
     }
     foreach ($array as $i => $part) {
         if ($i % 2 == 0) {
             $query .= $part;
             continue;
         }
         $value = array_shift($args);
         switch ($part) {
             case '?n':
                 $part = $this->escapeIdent($value);
                 break;
             case '?s':
                 $part = $this->escapeString($value);
                 break;
             case '?i':
                 $part = $this->escapeInt($value);
                 break;
             case '?a':
                 $part = $this->createIN($value);
                 break;
             case '?u':
                 $part = $this->createSET($value);
                 break;
             case '?p':
                 $part = $value;
                 break;
         }
         $query .= $part;
     }
     Mi::app()->log->query($query);
     return $query;
 }
Exemplo n.º 8
0
<?php

spl_autoload_register(function ($class) {
    if (file_exists(ROOT . '/application/models/' . $class . '.php')) {
        include ROOT . '/application/models/' . $class . '.php';
    } else {
        $map = Mi::app()->map;
        if (count($map) > 0) {
            foreach ($map as $path) {
                if (file_exists(ROOT . $path . $class . '.php')) {
                    include ROOT . $path . $class . '.php';
                }
            }
        }
    }
});