PHP无法在文件中读取我的html

时间:2017-07-08 08:29:04

标签: php html model-view-controller

我有一个模板类,我可以通过它回显文件。 我将我的文件的地址提供给模板类并将其回显。 我有4个名为的文件:索引,主题,主题,寄存器,所有这些文件都很完美但是topic.php是空的。我的代码就是寄存器控制器文件中的寄存器。我该怎么办?谢谢。

<?php 
$template = new template('templates/register.php');//include the template
//display template
echo $template;

4 个答案:

答案 0 :(得分:0)

尝试

<?php 
    $template = file_get_contents('templates/register.php'); //include the template
    //display template
    echo $template;

如果您想将代码用于其他目的,例如包含其内容,则应使用include('file_url');

参考http://uk3.php.net/manual/en/function.include.php

如果它不起作用,请告诉我

答案 1 :(得分:0)

看起来你正在尝试回显一个对象,而不是一个字符串。

它是否适用于此模板功能?

/**
 * Render template
 *
 * @param string $fileName
 * @param array $data
 * @return mixed
 */
function render($fileName, $data = array())
{
    ob_start();
    extract($data);
    require $fileName;
    $result = ob_get_contents();
    ob_end_clean();
    return $result;
}

用法

$template = render('templates/register.php');
echo $template;

答案 2 :(得分:0)

我没有足够的贡献,这就是我发布答案的原因。 你试过吗

include('templates/register.php');

您希望将HTML插入每个页面。我认为这可能有用

答案 3 :(得分:0)

我发现为什么会发生这种情况。这是因为在类文件夹中,我有一个模板类和一个主题类,主题是空的。 PHP进入这个目录(我不知道为什么!!!!)..并回显除主题文件以外的主题类。