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(); }
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]); } }
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'; }
public function actionIndex() { $this->pageTitle = 'Главная страница'; $this->render('index', ['time' => Mi::app()->timeRequest, 'data' => User::model()->findByPk(1)]); }
function __construct($class_name) { $this->model = new $class_name(); $this->db = Mi::app()->db; }
public function timeRequest() { $time = microtime(true) - Mi::app()->session->get('microtime'); return sprintf('%.4F сек.', $time); }
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; }
<?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'; } } } } });