layout | title |
---|---|
default |
Try displaying View from Controller |
-
Setting of Routing has finished in previous chapter
-
In this chapter,try displaying View with the created Routing
-
In this chapter,conduct the following part
-
Explanation about creating Controller and Rending method of View
-
Conduct explanation about creation and role of View (Twig)
-
- First, please create the following folder
- /src/Eccube/Controller/Tutorial
- Relevant Controller will gather into one folder.
- Creation method will be different in each
- Please create Directory as below
-
Next,create CrudController.php
-
Copy TopController, re-name
-
CrudController.php( contents will copy TopController.php)
- Modify as below
-
Try accessing into browser in order to check again
-
Please input「http://[ドメイン + インストールディレクトリ]/tutorial/crud」
-
Perhaps,next is not error, the following part will be displayed.
-
- Perhaps, there is no problem in setting of routing and Controller.
-
Add Twig file into the following folder
-
/src/Eccube/Resource/template/default/Tutorial
- Gather View of the relating Controller for each Folder.
- The creating method will be different in each environment, so I will separate.
- Please create Directory as below.
-
-
Next, create crud_top.twig
-
Copy index.twig, and rename
-
crud_top.twig( contents will copy index.twig)
- Conduct modification as below
- Modify the place where did 「echo」by controller in the following content
-
I will explain simply about Controller and Method
- Paramter : $app
- In $app,class that is used in EC-CUBE, has been storing.
- Correction is that content which is set in Application.php/ServiceProvider become structure, which is instanted, used when implementing.
- Here,I don't explain in detail, but remember that you just call many functions from [$app] to structure Application
- Name space : use Eccube\Application;
- In order to use [$app] that explained in 1., you have to specify name space out of scope of class
- If say simply, I will tell you place for storing class that use for controller.
- Path that specify in Name space will be different based on class which use, but in case use class that exist in [/src/Eccube], please specify relative path from [Eccube] (At the beginning, no need [])
- Name space : use Eccube\Controller\AbstractControler;
- I will set parent class of controller based on reason same above
- $app->render([表示したいTwigのパス])
- If transfer path of Twig into [render] as parameter, Twig of target will be analyzed, and converted into html.
- Normally,as return value of method of controller, if let return value of render as like that and [return],html that was converted, will be returned, screen is displayed.
- About path that specify as [引数(parameter)], [/src/Eccube/Resource/template/] is setting as route path
- Route path is setting when finished initialization of Application.php
- In case of Controller of Admin side,[/admin/] of folder above becomes target, In case of User screen, [/default/] becomes route folder.
- Paramter : $app
-
Try accessing in browser i
-
Please input「http://[ドメイン + インストールディレクトリ] into URL of browser
-
Contents which was described in
- Header and Footer has not displayed yet, but current status is exactly.
- The display setting of Header and footer will conduct later.
-
- Contents volume had also increased, so I will gather content of chapter
- I conducted the following part in this chapter
- Copy the existing Controller to create new controller
- Copy the existing Twig to create new Twig
- I explained the thing that based on Controller /Twig to gather into the relating folder.
- I explained that $app is transfered as parameter of method of controller,many functions have been stored.
- I explained that by converting Twig into html by render,set to be returned value of method, screen will be drawn.