dongni1892 2014-04-11 20:43
浏览 74
已采纳

注意:未定义的变量:模板和致命错误:在非对象上调用成员函数writePage()

I have a problem. When I run my site, the template error errors.

I get these two errors:

Notice: Undefined variable: template in /home/us22368/domains/******.nl/public_html/index.php on line 4 
Fatal error: Call to a member function writePage() on a non-object in /home/us22368/domains/******.nl/public_html/index.php on line 4

Some code:

index.php:

<?php
require_once('global.php');
$template->writePage('index');
$template->echoPage();
?>

My global.php includes this class (class.template.php) :

<?php
if (!class_exists('template')) {
    class template {
        public $template;
        public function writePage($pageName) {
            $file = 'app/themes/' . THEME . '/' . $pageName . '.html';
            if(!file_exists($file)) {
                die('The Page You Asked for does not exist.');
            } else {
            $this->content .= file_get_contents($file);
            }
        }
        public function echoPage() {
            echo $this->content;
        }
    }
}
?>

Is there anyone who can help me?

  • 写回答

1条回答 默认 最新

  • doutuo2829 2014-04-11 20:46
    关注

    In your index.php file you have to create an instance of template class:

    <?php
    require_once('global.php');
    $template = new template();
    $template->writePage('index');
    $template->echoPage();
    ?>
    

    Take a look to php documentation: http://www.php.net/manual/en/language.types.object.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记