[Explanatory article on task (2)] From inexperienced engineers, try to set three tasks that will be assigned to you in the early stages of your career.

Sep 5, 2020 PHP Symfony inexperienced engineer EC-CUBE4

Explanation of the previous article

Click here for the tasks that were asked

https://qiita.com/morry_48/items/7dea1145d2db8bb7f570

Task ② Add display wording on the screen

~ Get the data saved in the DB and display it on the screen ~

As for the outlook for the task

    1. Identification of display location
    1. Make sure that the data to be displayed is obtained from the database (if not, get it)
    1. Display the above data in the target location It becomes a procedure such as.

Start by finding the part to be displayed in the procedure of task ①. If you scroll the list.twig used in ① a little, there is a button to add to the cart, so the display part is just above it.

Next, if you look at the part where the product information of list.twig is displayed, you can see that it is displayed like Product.hogehoge. (The place where name is displayed is Product.name) Looking at the definition of Product, around line 145 {% for Product in pagination%} From that, you can see that the variable (array) called paginagion is expanded and displayed, so check the part that returns pagenation in the controller.

Since index () of ProductController.php is the target part, check the return part of this function. (Because the pagenation of this return is on the twig side)

Line 250.png https://gyazo.com/94a3af4709d2dc5623f05fec1e15b87a

In symfony, you can use dump to check the contents of variables, so use this to check the browser.

image.png

When you display it on the browser, you can see that the Product information is included by expanding the array of items. There is an item called description_detail here, so you can display this on the details screen. If it is not included here, it will be a task to change the conditions of the part where the data is acquired from the database and repair it so that the value will be passed.

Now that you know what to display, write the code in the target area you found earlier.

image.png

that’s all. When I checked the browser, detailed product information was displayed.

The task this time was to check and display whether the data could be acquired. I often use dump () for debugging to check the contents of variables. It depends on the framework, but in practical tasks, it is necessary to check whether the values are correct. I use it a lot, so I hope I can master it.