The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Rendering a php page

follypimpz's Avatar

follypimpz

20 Jun, 2017 02:57 PM

I have a project I am working on, and the structure is thus:
ivr
----error ->(954.html errors)
---img [ background images stored here]
---include [footer & header]
---Models [ db connect, user e.t.c]
---Modules [ logs, user dashboard, logs, settings e.t.c]
         - Login.php (resides inside the modules folder)
---Public [js, css, index.php]
---Twig templates [ Only just started reading about twigs, but here I will store all more twig templates]
---vendor

Inside my index.php file I have this
<?php
    use \Psr\Http\Message\ServerRequestInterface as Request;
    use \Psr\Http\Message\ResponseInterface as Response;
    
    require '../vendor/autoload.php';
    spl_autoload_register(function ($classname) {
        require "../models/" . $classname . ".php";
    });
    
    $config['displayErrorDetails'] = false;
    $app = new \Slim\App(["settings" => $config]);
    $container = $app->getContainer();
    // Register component on container
    $container['view'] = function ($container) {
        $view = new \Slim\Views\Twig(
            '/var/www/html/ivr/modules', ['cache' => false]);
        $env = $view->getEnvironment();
        $lexer = new Twig_Lexer($env, array(
            'tag_comment' => array('{#', '#}'),
            'tag_block' => array('{%', '%}'),
            'tag_variable' => array('[[', ']]'),
            'interpolation' => array('#{', '}'),
        ));
        $env->setLexer($lexer);
        // Instantiate and add Slim specific extension
        $basePath = rtrim(str_ireplace('index.php', '', $container['request']->getUri()->getBasePath()), '/');
        $view->addExtension(new Slim\Views\TwigExtension($container['router'], $basePath));
    
        return $view;
    };
    $app->get('/', function (Request $request, Response $response) {
        require_once "/var/www/html/ivr/modules/login.php";
        return $response->getBody();
        die();
      
    });

    $app->group('/img', function () use ($app) {
        
        $app->get('/logo', function ($request, $response, $args) {
            require_once "/var/www/html/ivr/img/logo.php";
            die();
        });

I want to know how once a user hits '/' route, it redirects them to the login page, while also loading my header.php which includes all my js, css, bootstrap links.

here is my header.php file
<?php
    //////////////////////////////////////////////////////////////////////////////
    // Created By : Chris Atkinson, Jack O'Connor & Denis Guliajev //
    // //
    // If you need any further information regarding //
    // the below code please email: //
    // //
    // [email blocked] //
    // [email blocked] //
    // [email blocked] //
    // //
    //////////////////////////////////////////////////////////////////////////////
    if (session_id() == '') {
        session_start();
    }
    
    require_once "/var/www/html/ivr/themes/themes.php";
    
    
    //If the current page isn't login run this.
    /*if ($current_pg != 'login' && $current_pg != 'forgot_pass' && $current_pg != 'no_pages_to_display') {
        
        require_once "/var/www/html/ivr/models/db_conn/Auth_conn.php";
        require_once "/var/www/html/ivr/models/Helpers.php";
        $auth_conn = Auth_conn::Instance()->getConnection();
    
        // validate if user account was not disabled
        if (!Helpers::Instance()->user_account_active()) {
            $_SESSION['error_message'] = 'Your personal account has been suspended.';
            header("Location: /ivr/logout.php");
            die();
        }
        
        if (!Helpers::Instance()->user_can_access_module($current_pg)) {
            $_SESSION['error_message'] = 'Unauthorised access attempt reported.';
            header("Location: /ivr/logout.php");
            die();
        }
    }*/
?>
<!DOCTYPE html >
<html lang="en-US">

<head>
    <meta http-equiv="Content-Type" content="text/html" charset="iso-8859-1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php
        echo (isset($page_title) && $page_title != '' ) ? $page_title : 'Log in';
    ?>
    <link rel='stylesheet' href='/ivr/public/css/bootstrap.css'/>
    <link rel='stylesheet' href='/ivr/public/js/libraries/angular-aside/angular-aside.css'/>
    <link rel="stylesheet" href="/ivr/public/js/libraries/angular-notify-master/styles/css/angular-notify-texture.css"
          id="notifyTheme">
    <link rel='stylesheet' href='/ivr/public/css/ivr_builder.css'/>
    <link rel="stylesheet" type="text/css" href="/ivr/public/css/custom.css">
    <script type="application/javascript" src="/ivr/public/js/libraries/angular.js"></script>
    <script type="application/javascript" src="/ivr/public/js/libraries/angular-animate.min.js"></script>

    <?php
        echo $top_bar;
    ?>
</head>
<body style="background: url('/img/background') no-repeat center fixed; -webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover; background-size: cover;">

<nav class="navbar navbar-default">
    <div class="container-fluid rebranded-top-header">
        <div class="navbar-header">
            <a class="navbar-brand" href="<?php echo $logo_href; ?>" style="padding-top: 3px;">
                <img id="header_brand_logo" alt="Brand" src="/img/logo" style="height: 42px;">
            </a>
        </div>
        <?php echo $nav_bar_message; ?>
    </div>
    <div class="container-fluid rebranded-header">
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <?php
                    echo $nav_bar_links;
                ?>
            </ul>
        </div>
    </div>
</nav>
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac