我有一個簡單的小枝條網站(無Symfony的安裝,所以config.yml是不是與此有關),這是我的代碼:嫩枝,截斷文字和PHP錯誤
.htaccess文件:
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
employees.html:
<html>
<head>
<style type="text/css">
table {
border-collapse: collapse;
}
tr.heading {
font-weight: bolder;
}
td {
border: 1px solid black;
padding: 0 0.5em;
}
</style>
</head>
<body>
<h2>Employees</h2>
<table>
<tr class="heading">
</tr>
{% for d in data %}
<tr>
<td>{{ d.name|escape }}</td>
<td>{{ d.role|escape }}</td>
<td>{{ d.salary|escape }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
員工爲varchar(255),作用是在MySQL的varchar(255)。
和我的代碼:
<?php
// include and register Twig auto-loader
include 'Twig/Autoloader.php';
Twig_Autoloader::register();
// attempt a connection
try {
$dbh = new PDO('mysql:dbname=employedb1;host=localhost', 'test', 'test');
} catch (PDOException $e) {
echo "Error: Could not connect. " . $e->getMessage();
}
// set error mode
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// attempt some queries
try {
// execute SELECT query
// store each row as an object
$sql = "SELECT name, role, salary FROM employees";
$sth = $dbh->query($sql);
while ($row = $sth->fetchObject()) {
$data[] = $row;
}
// close connection, clean up
unset($dbh);
// define template directory location
$loader = new Twig_Loader_Filesystem('templates');
// initialize Twig environment
$twig = new Twig_Environment($loader);
// load template
$template = $twig->loadTemplate('employees.html');
// set template variables
// render template
echo $template->render(array (
'data' => $data
));
} catch (Exception $e) {
die ('ERROR: ' . $e->getMessage());
}
?>
它的工作,直到我做了如下修改的index.php(原代碼添加註釋上面樹枝延伸,實際上不是): http://pastebin.com/QMaQXEip
它的工作,直到我添加了文本擴展名,並生成了以下錯誤: 致命錯誤:在第34行(第34行,引用上面的Twig_Extensions_Extension_Text())中找不到/Applications/MAMP/htdocs/employtesttwig/index.php中的類'Twig_Extensions_Extension_Text'。
爲什麼會發生這種情況,我該如何解決這個錯誤?
謝謝。
那麼,你有課嗎? – Maerlyn 2013-04-27 20:48:59