M
M
Maxim Spiridonov2014-09-13 11:10:44
PHP
Maxim Spiridonov, 2014-09-13 11:10:44

How to correctly include php files in smarty so that the contents of tpl files are displayed?

The problem is that when including php files in index.php, the content pages become empty, without any html/php code. Actually, here is my index.php, maybe I'm doing something wrong, I will be very grateful for your help.

<?php

error_reporting(0);
define('INCLUDE_CHECK',true);
include 'config.php'; 
include 'auth.php';
require '/libs/Smarty.class.php';

$path = dirname(__FILE__);
define('GLI',true);
$q = mysql_query("SELECT `name` FROM `rust_templates` WHERE `name`='default';",$sql);
$theme = mysql_result($q,0);
$tpl = new Smarty();
$theme_path = './templates/'.$theme.'/';
$tpl->template_dir = $theme_path;
$tpl->assign('path', $theme_path);
$tpl->caching = false;
//$tpl->compile_dir = './cache/';
$tpl->cache_dir = './cache/';

if(empty($_SESSION['id'])) {
    // Тут делаем авторизацию
    $tpl->assign('title', 'Авторизация');
    if(isset($_GET['error'])) {
        $tpl->assign('errno', 'Неверный логин или пароль!');
        $logger->WriteLine($log_date . "Неудачная попытка авторизации с ip: " . $_SERVER['REMOTE_ADDR']);
    }
    $tpl->assign('title', 'Новости');
    include("./modules/news.php");
    $tpl->display('guest.tpl');
} else {
    if(!isset($_GET['page']) || $_GET['page'] == '') {
        $tpl->assign('title', 'Новости');
        include("./modules/news.php");
        $tpl->assign('content', 'short-story.tpl');
        $tpl->assign('welcome1', 'Добро пожаловать '.$username.'!');
    } else {
        $full_path = './theme/'.$theme.'/'.$_GET['page'].'.tpl';
        if(!file_exists($full_path)) {
            $tpl->assign('title', 'Ошибка 404');
            $tpl->assign('content', 'error.tpl');
            $tpl->assign('welcome1', 'Ошибка 404');
            $tpl->assign('welcome2', '');
        }
        if($_GET['page'] == 'buy') {
            $tpl->assign('title', 'Покупка статуса');
            include("news.php");
            $tpl->assign('welcome1', 'Покупка статуса');
            $tpl->assign('welcome2', 'Здесь вы можете купить игровой статус');
        }
        if($_GET['page'] == 'quit') {
        session_destroy();
      header("Location: index.php");
    }
    }
    $tpl->display('index.tpl');
}
mysql_close($sql);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2014-09-13
@SilenceOfWinter

What about error logs? Are there any errors in the inserted files, do the variables overlap? You can try output buffering (ob_start\ob_get_clean)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question