Множественные правки во фреймворке - вывод, конфиг, описание методов
This commit is contained in:
parent
2ce0130b7d
commit
c92baf7171
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -77,4 +77,9 @@ class Model
|
|||
return $res ? $this : FALSE;
|
||||
}
|
||||
|
||||
function getValues()
|
||||
{
|
||||
return $this->_vals_;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
$config = array(
|
||||
return array(
|
||||
'title' => 'Интересные выходные вместе с wikipoints.ru',
|
||||
'DB' => array(
|
||||
'host' => 'localhost',
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
include_once dirname(__FILE__) . '/../ground/app.php';
|
||||
include_once dirname(__FILE__) . '/../ground/config.php';
|
||||
/*
|
||||
* Поехали! (с) Ю.А. Гагарин 12.04.1961
|
||||
*/
|
||||
|
||||
App::run($config);
|
||||
include_once dirname(__FILE__) . '/../ground/app.php';
|
||||
App::run('config.php');
|
||||
Loading…
Reference in New Issue