Google App Engineãfor phpã®
twigã®ãã³ãã¬ã¼ãã«ã¤ãã¦ã®ç¶ãã§ã
ä»åã¯listå¦çé¨åã«ã¤ãã¦è¨è¼ãã¾ã
ãªã¹ãå¦ç
å¦çæ¦è¦
webãã¼ã¸ãã¤ãããªãåºæ¬ä¸ã®åºæ¬ã®å¦ç
ã®listå¦çã§ã
ãã¼ã¿ã¨ãã¦ã¯User ãã¼ã¿ã§ã
('ID', 'name', '詳細', 'æ³')
ãã¡ãã®ãã¼ã¿ã表示ãããã¨æãã¾ã
ä½ã
ã«ãã´ãª | ããã°ã©ã | 詳細 |
---|---|---|
php | listpage.php | å®è¡ãããããã°ã©ã |
twig | base.html.twig | ãã¶ã¤ã³ã®ãã¼ã¹ã®ãã³ãã¬ã¼ãï¼ãªã¹ãã«ç¶æ¿ãã¾ãï¼ |
twig | listpage.html.twig | ãªã¹ãã®ãã³ãã¬ã¼ããã¡ã¤ã« |
twig | _userlistitem.html.twig | ã¦ã¼ã¶ã¼ã®ï¼è¡ã®ãã³ãã¬ã¼ããã¡ã¤ã« |
ã½ã¼ã¹
listpage.php
<!--?php require_once './vendor/autoload.php'; Twig_Autoloader::register(); //ãã³ãã¬ã¼ãã®èªã¿è¾¼ã¿ $loader = new Twig_Loader_Filesystem("views"); $twig = new Twig_Environment($loader); $template = $twig--->loadTemplate("listpage.html.twig"); //ãã¼ã¿ $users = array( array("id" => "1","name" =>"masa","description" => "ã¾ããéçºè ã§ã","age" => 35), array("id" => "2","name" =>"hiromi","description" => "ã¾ãã®ã§ããå«ã§ã","age" => 33), array("id" => "10","name" =>"æ²å¾","description" => "ã¾ãã®ç¶ã§ããé人ã§ã","age" => 66) ); $page = array( "description" => "ãµã¤ããããä½æãã¼ã«", "keywords" => "sitemap,tool", "title" => "ã¦ã¼ã¶ã¼ä¸è¦§", "users" => $users ); $template->display($page); ?>
ãã³ãã¬ã¼ããã¡ã¤ã«
listpage.html.twig
{% extends 'base.html.twig' %} {% block body %} <div class="row"> <div class="col-lg-12"> {% set columnname = ['ID', 'name', '詳細', 'æ³', 'æä½'] %} {% for column in columnname %} {% endfor %} {% for user in users %} {% include "_userlistitem.html.twig" %} {% endfor %} <table class="table table-bordered"> <tbody><tr><td>{{ column }}</td></tr><!--åç´ã«ãªã¹ãã§è¡¨ç¤ºãããã¿ã¼ã³ <tr> {% for column in row %} <td>{{ column }}</td> {% endfor %} <td>><a href="/user/edit.php?id={{ user.id }}" title="{{ user.name }}"> 1ç·¨é</a></td> </tr> --></tbody></table> </div><!-- /col-lg-12 --> </div><!-- /row --> {% endblock %}
ãªã¹ãã®ï¼è¡ç®ã®
_userlistitem.html.twig
{{ user.id }} {{ user.name }} {{ user.description }} {{ user.age }} <a href="/user/edit.php?id={{ user.id }}" title="{{ user.name }}"> 1ç·¨é</a>
å®è¡çµæ
ããã£ã½ããªãã¾ãã
æ管
ã»ãªã¹ãã®ï¼è¡ããã³ãã¬ã¼ãã«ãã¾ãã
ãããã¯ããªãã¦ãããã£ãããã»ã»ã»
ã»ãã¼ã¿åå¾ã®é¨åã¯ãæ¬æ¥ã¯DBã§ã
ï¼ç¾å¨ãã¯ã¾ã£ã¦ãã¦ãã¼ãã³ã¼ãã«ãªã£ã¦ãã¾ãï¼