-1
所以,我有這個奇怪的錯誤:Catchable fatal error: Object of class Template_Standard could not be converted to string in C:\wamp\www\game\template\standard\index.php on line 23
開捕致命錯誤:類Template_Standard的對象無法轉換爲字符串
它basicly由這兩個文件:
template_standard.php(功能文件):
<?php
if (!defined('INCLUDED')) exit;
class Template_Standard
{
public function print_login_text()
{
global $user_functions, $path;
if ($user_functions -> is_logged_in())
{
return '<p>' . WELCOME_BACK . $_SESSION['username'] . '</p>';
}
else
{
return '<div id="login_form">
<form action="' . $path . 'login" method="post">
<p>
<input type="text" name="name"/> ' . NAME . '<br/>
<input type="password" name="pass"/> ' . PASSWORD . '
</p>
<p><input type="submit" value="' . LOG_IN . '" class="button"/></p>
<p><a href="' . $path . 'register" onclick="get_register();return false">' . REGISTER . '</a></p>
</form>
</div>';
}
}
public function print_menu()
{
global $path;
$html = '<ul id="menu">';
$html .= '<li><a href="' . $path . '"><img src="' . $path . 'media/menu/home.png" width="100" height="35"/></a></li>';
$html .= '<li><a href="' . $path . 'register"><img src="' . $path . 'media/menu/register.png" width="100" height="35"/></a></li>';
$html .= '</ul>';
return $html;
}
}
?>
而且模板文件:
<?php
if (!defined('INCLUDED')) exit;
require '././functions/template_standard.php';
$template = new Template_Standard();
$register_form = '<form action="' . $path . 'register" method="post">\\
<p>\\
<input type="text" name="name"/> ' . NAME . '<br/>\\
<input type="password" name="pass"/> ' . PASSWORD . '<br/>\\
<input type="password" name="pass2"/> ' . PASSWORD_AGAIN . '<br/>\\
<input type="text" name="email"/> ' . EMAIL . '<br/>\\
</p>\\
<p><input type="submit" value="' . REGISTER . '" class="button"/></p>\\
</form>';
$head .= <<<HTML
<link href="{$path}template/$template/style.css" rel="stylesheet" type="text/css"></link>
<!--[if lt IE 9]><style type="text/css">#content{border:1px solid #333;}</style><![endif]-->
<script type="text/javascript">
function get_register()
{
var speed = 'fast';
var html = '$register_form'; // Error here
$('#login_form').fadeOut(speed, function(){
$('#login_form').html(html).fadeIn(speed);
});
return false;
}
$(document).ready(function(){
if (screen.height < 768) {
$('#footer').hide();
} // Fourth error, and so on
}); // Third error here
</script> // If I remove the place with the first error, the second is here ...
HTML;
$body_start .= '<div id="content"><a href="' . $path . '"><div id="header"><img src="' . $path . 'media/header/logo.jpg" width="600" height="150"/></div></a><div id="menu-container">' . $template -> print_menu() . '</div><br style="clea:left"/><div id="content-left">';
$body_end .= '</div><div id="content-right">' . $template -> print_login_text() . '</div></div><div id="footer"><div style="float:right;text-align:right">Lorem ipsum ...</div>Copyright © 2012 Jacob<br/>All rights reserved</div>';
?>
問題是,如果我刪除錯誤行,它只會在HTML事件內的另一行中引發錯誤。解決它的唯一方法是刪除它中的所有內容。 另外,如果我在模板文件中直接使用函數,它會很好用。
哦,我明白了。接受有兩個相同名稱的變量。謝謝! – SnackerSWE 2012-03-11 11:52:40