2013-04-27 2 views
1

텍스트와 PHP 오류를 절단 (더 심포니 설치, 그래서 config.yml 여기에 관련이 없습니다)이 내 코드입니다 :는 나뭇 가지, 나는 작은 간단한 나뭇 가지 사이트가

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 행의 /Applications/MAMP/htdocs/employtesttwig/index.php (위의 Twig_Extensions_Extension_Text()를 참조하는 34 행)에 클래스 'Twig_Extensions_Extension_Text'클래스가 없습니다.

왜 이런 일이 발생하며 어떻게이 오류를 해결할 수 있습니까?

감사합니다.

+0

글쎄, 그 수업을해야합니까? – Maerlyn

답변

0

당신이 말한대로, 당신은 단지 사용자 정의 설치에서 나뭇 가지를 사용합니다.
https://github.com/fabpot/Twig-extensions

없는 클래스 : Twig_Extensions_Extension_Text가 나뭇 가지 코어의 나뭇 가지 - 확장 lib 디렉토리의 일부가 아닌
난 당신이 여기에서 찾을 수 있습니다 나뭇 가지-확장을 추가해야 할 것 같아요.

패키지를 다운로드했는데 필요한 파일이 포함되었거나 자동로드 되었습니까?

이 문서 인용하기

:

Of course, you need to first load the extension file by either using require_once() or by using an autoloader (see spl_autoload_register()).