layout | title |
---|---|
default |
Try transferring variable to screen |
-
In the previous chapter, I conducted Controller and creating/rendering Twig
-
In oder to build WEB Application,you need to transfer info from Controller to View. In this chapter,just use the basic parts.
-
In this chapter, conduct the following part
-
Explain about defining View variable for Controller
-
Explain how to transfer variable when rendering Controller
-
Explain how to display varible that received from Controller by Twig
-
-
Define variable in Controller,give variable that defined already in method [render] as parameter by associative array
-
In this time,「key」 becomes the optional character string,but when call variable in Twig side, it becomes the name
-
Modify CrudController.php as below quickly
- /src/Eccube/Controller/Tutorial/CrudController.php
-
Eplain the modification
-
If transfer associative array for the second paramter of render method, you will be able to operate variable that transferred in twig. In this time, based on key of associative array to conduct operation of variable
-
Key of associative array is optional.
-
-
Add the display of variable that transferred by associative array in Controller, into Twig
-
Modify as below
- Tutorial/crud_top.twig
-
Explain simply about the addition contents of this time
-
Display variable that set in {{}}Twig by Controller
-
There are 3 kinds of block(1.の{{}}) of Twig
| ブロック種別 | 適用対象 | 凡例 | |------|------| | {{}} | 変数の中身を表示 | {{ viewstr|nl2b }} | | {%%} | ブロック内でロジックを記述する | {% if myvar is ... %} | | {##} | コメントアウト | {# DB取得内容を表示... #} |
-
Use separately 3 kinds above in order to structure View
-
-
Try accessing into Browser to confirm finally
-
Please input「http://[ドメイン + インストールディレクトリ]/tutorial/crud」in URL of browser
-
Contents of variable that defined in Controller, is displayed.
-
-
In this chapter, I studied the following part
-
I explained how to add View variable to render method in Controller
-
I conducted the display of varible of Twig
-
I explained kind of Block of Twig
-
- The following variable has been intialized by 「Application.php」, storing, so you can call directly from all Twigs
変数名 | 詳細情報 |
---|---|
BaseInfo | 管理画面 > 設定 > 基本情報設定 > ショップマスターで保存した内容 |
title | ページタイトル |
- About the call method will make call as below.
例. {{ BaseInfo.カラム名 }}
- About the detail Twig structure, I will explain in next chapter