How to build the architecture of Symfony 4?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
19 views
1 time doing a Symfony project and I'm not sure how to build the architecture. Please show the code that I have, and then questions.
The project will RestApi. Accept json, give json format JSend.
The architecture is roughly as follows:
Controller -> Service -> Repository -> Entity
Example: the creation of the product. The product has a ManyToOne relationship with Workspace.
ProductController:
public function store( Request $request, ProductStoreValidation $productStoreValidation, ValidationTransformer $validationTransformer ): Response { $body = $request->request->all(); $violations = $productStoreValidation->validate($body); if ($violations->count()) { $errorsData = $validationTransformer->transform($violations); throw new ValidationRawException($errorsData); } $product = $this->productService->addProduct($body); $data = [ 'product' => $product ]; $response = new JSendResponse(JSendResponse::SUCCESS, $data); return new JsonResponse($response, Response::HTTP_CREATED); }

by | 19 views

2 Answers

0 like 0 dislike
How do I collect the project Symphony
composer self-update
composer require symfony/symfony-skeletone (requires the PHP memory limit to more than 1800M)
Never coach, don anything at the start manually - the First rule =)
If You suddenly need authorization from korobki -
php bin/console make:auth
First Your controller
php bin/console make:controller
> MyShopController
Need a class for connection with DB
php bin/console make:entity
> Shop
in the process You will write Repository created avtomaticheski
We forgot about the database! Nephites do a few more commands)
php bin/console doctrine:database:create
Now you can upload tables:
php bin/console make:migration
Now to see the tables in the database itself say command
php bin/console doctrine:migrations:migrate
Voila - it's Magic Symphonies)

If there is contact

Specifically in question-
I have a router looks like this:
app_product
path: /product/{slug}/{action}
controller: App\\Controller\\ProductController:indexAction

The link /product/update/#id
POST ajax request
ProductController:
$post = $request->request->all(); // all POST requests
$product = new Product;
$product->setPrice($post['price']);
...
/product/show/#id
Loaded the page with the product.
This is a concrete example of logic
by
0 like 0 dislike
The doctrine has Filters to solve your troubles with validation (on habré there are a couple of articles).
My personal opinion - in projects with waterfall and eternal business objectives of the services. This will save you from troubles. More code nonsense, It's(code) your, it all structured and clear. Do not disturb the Entity with the logic, it's not AR Yii.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,389 users