-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsymfony.commands.txt
595 lines (457 loc) · 18.8 KB
/
symfony.commands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
>>>>>>>> Symfony Commands <<<<<<<<<
--------------------------------------
Keys: symfony6 api, twig extends
--------------------------------------
-----------------------------------------------------------------------------
Symfony 2.7, 2.8:
1. Execute the php app/console server:run command.
2. Browse to the http://localhost:8000 URL.
3. Read the Documentation at http://symfony.com/doc
//c:/xampp/htdocs/symfony>
composer create-projet symfony/skeleton sf4
composer require symfony/var-dumper
php app/console
php app/console debug:router
php app/console service:run
php app/console generate:controller
bin/console make:crud BlogPost
php bin/console
bin/console make:form
php bin/console debug:twig
php bin/console debug:twig --filter=date
php bin/console debug:twig @Twig/Exception/error.html.twig
composer require symfony/asset
//Save entities(or Scheme tables) in Database
php bin/console doctrine:schema:update --force
php bin/console doctrine:migrations:diff
------------------------------------------------------------------------------------
//-------> php bin/console <----------------
C:\xampp\htdocs\symfony>php bin/console
Symfony 4.3.2 (env: dev, debug: true)
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-e, --env=ENV The Environment name. [default: "dev"]
--no-debug Switches off debug mode.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
/////////////------>> Available commands: <<----------//////////////////
about Displays information about the current project
help Displays help for a command
list Lists commands
assets
assets:install Installs bundles web assets under a public directory
cache
cache:clear Clears the cache
cache:pool:clear Clears cache pools
cache:pool:delete Deletes an item from a cache pool
cache:pool:list List available cache pools
cache:pool:prune Prunes cache pools
cache:warmup Warms up an empty cache
config
config:dump-reference Dumps the default configuration for an extension
debug
debug:autowiring Lists classes/interfaces you can use for autowiring
debug:config Dumps the current configuration for an extension
debug:container Displays current services for an application
debug:event-dispatcher Displays configured listeners for an application
debug:form Displays form type information
debug:router Displays current routes for an application
debug:twig Shows a list of twig functions, filters, globals and tests
doctrine
doctrine:cache:clear-collection-region Clear a second-level cache collection region
doctrine:cache:clear-entity-region Clear a second-level cache entity region
doctrine:cache:clear-metadata Clears all metadata cache for an entity manager
doctrine:cache:clear-query Clears all query cache for an entity manager
doctrine:cache:clear-query-region Clear a second-level cache query region
doctrine:cache:clear-result Clears result cache for an entity manager
doctrine:cache:contains Check if a cache entry exists
doctrine:cache:delete Delete a cache entry
doctrine:cache:flush [doctrine:cache:clear] Flush a given cache
doctrine:cache:stats Get stats on a given cache provider
doctrine:database:create Creates the configured database
doctrine:database:drop Drops the configured database
doctrine:database:import Import SQL file(s) directly to Database.
doctrine:ensure-production-settings Verify that Doctrine is properly configured for a production environment
doctrine:generate:entities [generate:doctrine:entities] Generates entity classes and method stubs from your mapping information
doctrine:mapping:convert [orm:convert:mapping] Convert mapping information between supported formats
doctrine:mapping:import Imports mapping information from an existing database
doctrine:mapping:info
doctrine:migrations:diff [diff] Generate a migration by comparing your current database to your mapping information.
doctrine:migrations:dump-schema [dump-schema] Dump the schema for your database to a migration.
doctrine:migrations:execute [execute] Execute a single migration version up or down manually.
doctrine:migrations:generate [generate] Generate a blank migration class.
doctrine:migrations:latest [latest] Outputs the latest version number
doctrine:migrations:migrate [migrate] Execute a migration to a specified version or the latest available version.
doctrine:migrations:rollup [rollup] Rollup migrations by deleting all tracked versions and insert the one version that exists.
doctrine:migrations:status [status] View the status of a set of migrations.
doctrine:migrations:up-to-date [up-to-date] Tells you if your schema is up-to-date.
doctrine:migrations:version [version] Manually add and delete migration versions from the version table.
doctrine:query:dql Executes arbitrary DQL directly from the command line
doctrine:query:sql Executes arbitrary SQL directly from the command line.
doctrine:schema:create Executes (or dumps) the SQL needed to generate the database schema
doctrine:schema:drop Executes (or dumps) the SQL needed to drop the current database schema
doctrine:schema:update Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata
doctrine:schema:validate Validate the mapping files
lint
lint:twig Lints a template and outputs encountered errors
lint:yaml Lints a file and outputs encountered errors
make
make:auth Creates a Guard authenticator of different flavors
make:command Creates a new console command class
make:controller Creates a new controller class
make:crud Creates CRUD for Doctrine entity class
make:entity Creates or updates a Doctrine entity class, and optionally an API Platform resource
make:fixtures Creates a new class to load Doctrine fixtures
make:form Creates a new form class
make:functional-test Creates a new functional test class
make:migration Creates a new migration based on database changes
make:registration-form Creates a new registration form system
make:serializer:encoder Creates a new serializer encoder class
make:serializer:normalizer Creates a new serializer normalizer class
make:subscriber Creates a new event subscriber class
make:twig-extension Creates a new Twig extension class
make:unit-test Creates a new unit test class
make:user Creates a new security user class
make:validator Creates a new validator and constraint class
make:voter Creates a new security voter class
router
router:match Helps debug routes by simulating a path info match
security
security:encode-password Encodes a password
-----------------------------------------------------------------------------------
>>>>>>>>>>>>> Symfony 6 <<<<<<<<<<<<<<<<<<<<<
Databases:
composer require symfony/orm-pack
composer require --dev symfony/maker-bundle
php bin/console doctrine:database:create
php bin/console make:entity --regenerate
php bin/console make:migration
php bin/console doctrine:migrations:migrate
php bin/console dbal:run-sql 'SELECT * FROM product'
php bin/console make:controller ProductController
composer require sensio/framework-extra-bundle
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
<<<<<< symfony6 api <<<<<<<<<<<
//src/controller/ProductController.php
<?php
namespace App\Controller;
use App\Entity\Product;
use Doctrine\Persistence\ManagerRegistry;
//use App\Repository\ProductRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class ProductController extends AbstractController
{
#[Route('/no', name: 'list_products')]
public function index(ManagerRegistry $doctrine): Response
{
$product = $doctrine->getRepository(Product::class)->findAll();
return $this->json([
'products' => $product
]);
}
/**
* @Route("/add_products", name="product_add")
*/
public function add_product(ManagerRegistry $doctrine, request $request):Response
{
$product = new Product();
$parameter = json_decode($request->getContent(), true);
$product->setName($parameter['name']);
$product->setPrice($parameter['price']);
$product->setQty($parameter['qty']);
$product_create = $doctrine->getRepository(Product::class)->add($product);
// -- OR --
//$em = $doctrine->getManager();
//$em->persist($product);
//$em->flush($product);
return $this->json([
'product' => "Saved"
]);
}
/**
* @Route("/show/{id}", name="product_show")
*/
public function show(ManagerRegistry $doctrine, int $id): Response
{
$product = $doctrine->getRepository(Product::class)->find($id);
if (!$product) {
throw $this->createNotFoundException(
'No product found for id '.$id
);
}
//return new Response('Check out this great product: '.$product->getName());
return $this->json([
'product' => $product
]);
}
/**
* @Route("/update_product/{id}", name="product_update")
*/
public function update(ManagerRegistry $doctrine, request $request, $id):Response
{
$entityManager = $doctrine->getManager();
$product = $entityManager->getRepository(Product::class)->find($id);
$parameter = json_decode($request->getContent(), true);
$product->setName($parameter['name']);
$product->setPrice($parameter['price']);
$product->setQty($parameter['qty']);
//$entityManager->flush();
$product_create = $doctrine->getRepository(Product::class)->add($product);
return $this->json([
'product' => 'Updated'
]);
}
/**
* @Route("/delete_product/{id}", name="product_delete")
*/
public function delete_product(ManagerRegistry $doctrine, $id):Response
{
$entityManager = $doctrine->getManager();
$product = $entityManager->getRepository(Product::class)->find($id);
/*
if (!$product) {
throw $this->createNotFoundException(
'No product found for id '.$id
);
}
*/
$entityManager->getRepository(Product::class)->remove($product);
return $this->json([
'product' => 'Deleted'
]);
}
/**ss
* @Route("/prac", name="product_prac")
*/
public function prac(ManagerRegistry $doctrine):Response
{
$entityManager = $doctrine->getManager();
$product = $entityManager->getRepository(Product::class)->find($id);
/*s
if (!$product) {
throw $this->createNotFoundException(
'No product found for id '.$id
);
}
*/
//$entityManager->getRepository(Product::class)->remove($product);
return $this->json([
'message' => 'Practicing'
]);
}
}
...........
//src/Entity/Product.php
<?php
namespace App\Entity;
use App\Repository\ProductRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
class Product
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
public $id;
#[ORM\Column(type: 'string', length: 255)]
public $name;
#[ORM\Column(type: 'float')]
public $price;
#[ORM\Column(type: 'integer')]
public $qty;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getQty(): ?int
{
return $this->qty;
}
public function setQty(int $qty): self
{
$this->qty = $qty;
return $this;
}
}
.................
//src/Repository/ProductRepository.php
<?php
namespace App\Repository;
use App\Entity\Product;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Product|null find($id, $lockMode = null, $lockVersion = null)
* @method Product|null findOneBy(array $criteria, array $orderBy = null)
* @method Product[] findAll()
* @method Product[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ProductRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Product::class);
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(Product $entity, bool $flush = true): void
{
$this->_em->persist($entity);
if ($flush) {
$this->_em->flush();
}
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(Product $entity, bool $flush = true): void
{
$this->_em->remove($entity);
if ($flush) {
$this->_em->flush();
}
}
}
.................
//templates/base.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>">
{# Run `composer require symfony/webpack-encore-bundle` to start using Symfony UX #}
{% block stylesheets %}
{{ encore_entry_link_tags('app') }}
{% endblock %}
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
{% endblock %}
</head>
<body>
{% block body %}
<h1>This is base twig template rendering</h1>
{% endblock %}
</body>
</html>
.................
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
>>>>>> Twig Template Extends <<<<<<<
//--> layout/base.html.twig (Parent Template) <--// j
{# templates/layout/base.html.twig #}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}My Application{% endblock %}</title>
{% block stylesheets %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
{% endblock %}
{% block javascripts %}
{% endblock %}
</head>
<body>
{% block body %}
<div id="sidebar">
{% block sidebar %}
<ul>
<li><a href="{{ path('app_index') }}">Home</a></li>
<li><a href="{{ path('app_contact') }}">Blog</a></li>
</ul>
{% endblock %}
</div>
<div id="content" class="container">
{% block content %}
{% endblock %}
</div>
{% endblock %}
</body>
</html>
//--> Child Template <--//
//templates/layout/index.html.twig
{% extends 'layout/base.html.twig' %}
{% block title %}Lising Data{% endblock %}
{% block content %}
<h1>Users</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.id}}</td>
<td>{{ user.name}}</td>
<td>{{ user.email}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
//templates/layout/contact.html.twig
{% extends 'layout/base.html.twig' %}
{% block title %}Contact{% endblock %}
{% block content %}
<h3>Contacts</h3>
{% endblock %}
//Controller
class UserController extends AbstractController
{
#[Route('/', name: 'app_index')]
public function index(ManagerRegistry $doctrine, Request $request)
{
$em = $doctrine->getManager();
$users = $em->getRepository(User::class)->findAll();
// print_r($users);
return $this->render('users/index.html.twig', ['users' => $users]);
}
#[Route('/contact', name: 'app_contact')]
public function contact()
{
return $this->render('users/contact.html.twig');
}
}
-------------------------------------------------------------------
-------------------------------------------------------------------