rebellious
Новичок
Дата регистрации:
08.04.2015 23:12:16
Сообщений: 1
Дошел до написания движка. И тут начались проблемы. Дошел до вывода статей на главную страницу и начала появляться ошибка 500. При том все остальные элементы как меню прекрасно отображаются. Ошибка появляется только когда в базе есть статьи, если их нет, то сайт работает. Если кто может подсказать в чем проблема, то буду благодарен.
<?php
require_once "modules_class.php";
class ArticleContent extends Modules {
private $article_info;
public function __construct($db) {
parent::__construct($db);
$this->article_info = $this->article->get($this->data["id"]);
}
protected function getTitle(){
return $this->article_info["title"];
}
protected function getDescription() {
return $this->article_info["meta_desc"];
}
protected function getKeyWords(){
return $this->article_info["meta_key"];
}
protected function getMiddle(){
return $this->getArticle();
}
private function getArticle() {
$sr["title"] = $this->article_info["title"];
$sr["full_text"] = $this->article_info["full_text"];
$sr["date"] = $this->formatDate($this->article_info["date"]);
return $this->getReplaceTemplate($sr, "article"
}
}
?>
<?php
require_once "global_class.php";
class Article extends GlobalClass {
public function __construct($db){
parent::__construct("articles", $db);
}
public function getAllSortDate() {
return $this->getAll("date", false);
}
public function getAllOnSectionID($section_id) {
return $this->getAllOnField("section_id", $section_id, "date", false);
}
}
?>
<?php
require_once "config_class.php";
require_once "article_class.php";
require_once "section_class.php";
require_once "user_class.php";
require_once "menu_class.php";
require_once "banner_class.php";
require_once "message_class.php";
abstract class Modules {
protected $config;
protected $article;
protected $section;
protected $user;
protected $menu;
protected $banner;
protected $message;
protected $data;
public function __construct($db) {
session_start();
$this->config = new Config();
$this->article = new Article($db);
$this->section = new Section($db);
$this->user = new User($db);
$this->menu = new Menu($db);
$this->banner = new Banner($db);
$this->message = new Message();
$this->data = $this->secureData($_GET);
}
public function getContent(){
$sr["title"] = $this->getTitle();
$sr["meta_desc"] = $this->getDescription();
$sr["meta_key"] = $this->getKeyWords();
$sr["menu"] = $this->getMenu();
$sr["auth_user"] = $this->getAuthUser();
$sr["banners"] = $this->getBanners();
$sr["top"] = $this->getTop();
$sr["middle"] = $this->getMiddle();
$sr["bottom"] = $this->getBottom();
return $this->getReplaceTemplate($sr, "main"
}
abstract protected function getTitle() ;
abstract protected function getDescription ();
abstract protected function getKeyWords() ;
abstract protected function getMiddle();
protected function getMenu() {
$menu = $this->menu->getAll();
for ($i = 0; $i < count($menu); $i++) {
$sr["title"] = $menu[$i]["title"];
$sr["link"] = $menu[$i]["link"];
$text .= $this->getReplaceTemplate($sr, "menu_item"
}
return $text;
}
protected function getAuthUser() {
$sr["message_auth"] = "";
return $this->getReplaceTemplate($sr, "form_auth"
}
protected function getBanners() {
$banners = $this->banner->getAll();
for ($i = 0; $i < count($banners); $i++) {
$sr["code"] = $banners[$i]["code"];
$text .= $this->getReplaceTemplate($sr, "banner"
}
return $text;
}
protected function getTop() {
return "";
}
protected function getBottom() {
return "";
}
private function secureData($data) {
foreach($data as $key => $value) {
if (is_array($value)) $this->secureData($value);
else $data[$key] = htmlspecialchars($value);
}
return $data;
}
protected function getBlogArticles($articles, $page){
$start = ($page - 1) * $this->config->count_blog;
$end = (count($articles) > $start + $this->config->count_blog)? $start + $this->config->count_blog: count($articles);
for ($i = $start; $i < $end; $i++) {
$sr["title"] = $articles[$i]["title"];
$sr["intro_text"] = $articles[$i]["intro_text"];
$sr["date"] = $this->formatDate($articles[$i]["date"]);
$sr["link_article"] = $this->config->address."?view=article&id=".$articles[$i]["id"];
$text .= $this->getReplaceTemplate($sr, "article_intro"
}
return $text;
}
protected function formatDate($time) {
return date("Y-m-d H:i:s", $time);
}
protected function getPagination($count, $count_on_page, $link) {
$count_pages = ceil($count / $count_on_page);
$sr["number"] = 1;
$sr["link"] = $link;
$pages = $this->getReplaceTemplate($sr, "number_page"
$sym = (strpos($link, "?" !== false)? "&": "?";
for ($i = 2; $i = $count_pages; $i++){
$sr["number"] = $i;
$sr["link"] = $link.$sym."page=$i";
$pages .= $this->getReplaceTemplate($sr, "number_page"
}
$els["number_pages"] = $pages;
return $this->getReplaceTemplate($els, "pagination"
}
protected function getTemplate($name){
$text = file_get_contents($this->config->dir_tmpl.$name.".tpl"
return str_replace("%address%", $this->config->address, $text);
}
protected function getReplaceTemplate($sr, $template) {
return $this->getReplaceContent($sr, $this->getTemplate($template));
}
private function getReplaceContent($sr, $content) {
$search = array();
$replace = array();
$i = 0;
foreach ($sr as $key => $value) {
$search[$i] = "%$key%";
$replace[$i] = $value;
$i++;
}
return str_replace($search, $replace, $content);
}
}
?>
<?php
require_once "modules_class.php";
class FrontPageContent extends Modules {
private $articles;
private $page;
public function __construct($db) {
parent::__construct($db);
$this->articles = $this->article->getAllSortDate();
$this->page = (isset($this->data["page"]))? $this->data["page"]: 1;
}
protected function getTitle(){
if ($this->page > 1) return "Справочние по PHP - Страница ".$this->page;
else return "Справочник PHP";
}
protected function getDescription() {
return "Справочник функций по php";
}
protected function getKeyWords(){
return "справочник php, справочник";
}
protected function getTop() {
return $this->getTemplate("main_article"
}
protected function getMiddle(){
return $this->getBlogArticles($this->articles, $this->page);
}
protected function getBottom() {
return $this->getPagination(count($this->articles), $this->config->count_blog, $this->config->address);
}
}
?>
Вот несколько классов в которых возможно есть ошибка. Курс неоднократно пересматривал, но ничего такого не находил