diff --git a/ground/app.php b/ground/app.php index 8b18331..ebbd904 100644 --- a/ground/app.php +++ b/ground/app.php @@ -54,12 +54,12 @@ class App /** * Основной метод для запуска приложения. - * @param array $config + * @param string $config имя файла с конфигом */ - public static function run($config) + public static function run($config = '') { ob_start(); - self::$config = is_array($config) ? $config : array(); + self::$config = $config ? include_once $config : array(); self::parseUrl(); if (self::getConfig('DB')) @@ -90,12 +90,17 @@ class App public static function error404($message = '') { header("HTTP/1.0 404 Not Found"); - die('Error 404 '.$message); + die($message ? $message : '404 - Not Found'); } - public static function redirect($url) + /** + * Перенаправление на другой URL + * @param type $url + * @param type $httpCode - по умолчанию 307, временный редирект + */ + public static function redirect($url, $httpCode = 307) { - header("Location: " . $url); + header('Location: ' . $url, true, $httpCode); } /** diff --git a/ground/classes/Controller.php b/ground/classes/Controller.php index b270ac0..d53d630 100644 --- a/ground/classes/Controller.php +++ b/ground/classes/Controller.php @@ -24,6 +24,13 @@ abstract class Controller } } + /** + * Рендерит шаблон без лейаута. + * @param string $template - имя шаблона + * @param array $data - передаваемые параметры + * @param bool $return - вернуть результат в виде строки + * @return string + */ static function renderPartial($template, $data, $return = false) { if (!file_exists(App::getBasedir() . 'views/' . $template)) @@ -41,12 +48,18 @@ abstract class Controller $newContentFormBuffer_temp = ob_get_clean(); echo $oldContentFormBuffer_temp; return $newContentFormBuffer_temp; - } else - { - echo $newContentFormBuffer_temp; } + + return true; } + /** + * Рендерит шаблон и вписывает его в лейаут. + * @param string $template - имя шаблона + * @param array $data - передаваемые параметры + * @param bool $return - вернуть результат в виде строки + * @return string + */ static function render($template, $data, $return = false) { $content = self::renderPartial($template, $data, true); diff --git a/ground/classes/Model.php b/ground/classes/Model.php index b9e8a70..0bb0ddb 100644 --- a/ground/classes/Model.php +++ b/ground/classes/Model.php @@ -77,4 +77,9 @@ class Model return $res ? $this : FALSE; } + function getValues() + { + return $this->_vals_; + } + } diff --git a/ground/config_template.php b/ground/config_template.php index e641c43..43bc0ff 100644 --- a/ground/config_template.php +++ b/ground/config_template.php @@ -1,6 +1,6 @@ 'Интересные выходные вместе с wikipoints.ru', 'DB' => array( 'host' => 'localhost', diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 3338604..416a624 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -15,8 +15,8 @@ class JsonController extends Controller $categories = $categories->getAll(); foreach ($points as &$point) { - $point['categoryIcon'] = $categories[$point['categoryId']]['icon']; - $point['categoryName'] = $categories[$point['categoryId']]['name']; + $point->categoryIcon = $categories[$point->categoryId]['icon']; + $point->categoryName = $categories[$point->categoryId]['name']; } self::renderPartial('json.php', array( @@ -38,10 +38,10 @@ class JsonController extends Controller $categories = new Category(); $categories = $categories->getAll(); - $point['categoryIcon'] = $categories[$point['categoryId']]['icon']; - $point['categoryName'] = $categories[$point['categoryId']]['name']; + $point->categoryIcon = $categories[$point->categoryId]['icon']; + $point->categoryName = $categories[$point->categoryId]['name']; - self::renderPartial('json.php', $point); + self::renderPartial('json.php', $point->getValues()); } else { App::error404(); diff --git a/public/index.php b/public/index.php index c5f48d0..9cffb71 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,8 @@