0

I am using these codes so that I can pass the file needed or other attribute through variables but it is not working properly. I don't know what the problem is because the code looks pretty fine to me. Index page does not show any content from header's page.

helper.php

<?php
function render($template, $data = array())
{
    $path = $template . ' .$php ';
    if(file_exists($path))
    {
        extract($data);
        require($path);
    }
}

header.php

<?php require_once('helper.php') ?>
<!doctype html>
<head>
    <title><?php echo htmlspecialchars($title); ?></title>
</head>
<body>

Index.php

<?php
    require_once('helper.php');
    render('header', array('title' => 'Index'));
?>
1
  • Well, at least one issue will be ' .$php '. Unless you really have a space before the extension . and a $ before php, but that seems unlikely. Commented Sep 14, 2016 at 13:35

2 Answers 2

1

This is wrong:

$path = $template . ' .$php ';

You are adding spaces and a $ sign to your path:

$path = $template . '.php';
Sign up to request clarification or add additional context in comments.

Comments

0

I believe you must want this line

$path = $template . ' .$php ';

to actually be this:

$path = $template . '.php';

1 Comment

yeah..didnt saw it through, stupid mistake. It is working now, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.