symfony practice
//TODO به اینا لینک و کد اضافه کن
- composer (global) 2
- php
- symfony
- elastic search
- PHPStorm
- PHP Annotations
- and Symfony plugin
and other stuff :)))
to check requirements on machine link
symfony check:requirements
everything is fine, next:
- full bundle:
symfony new my_project_name --full
- command line app:
symfony new my_project_name
- to set versions at lts or currently developing version:
symfony new my_project_name --version=lts
symfony new my_project_name --version=next
- demo project
symfony new my_project_name --demo
start server: symfony server:start
default server: http://localhost:8000/
information about the project: php bin/console about
to automate downloading bundles and the most common tasks of Symfony applications we use Flex.
به زبان ساده کامندهایی به کامپوزر اضافه میکنه که استفاده ازش رو راحت میکنه. مثلا قبلا باید کلی مینوشتی الان یه کلمه مینویسی فلان چیز رو بگیر و میگیره
we call bundels as recepie
to add Flex: composer require symfony/flex
more here
to add more bundles and recepie:
composer require annotations asset orm-pack twig logger mailer form security translation validator
to be in dev env:
composer require
--dev
dotenv maker-bundle orm-fixtures profiler
Reinstall all dependencies: ( puting junk in config/ )
$ rm -rf vendor/*
$ composer install
default services in services.yaml //TODO 6 and after from flex are not done link
packs: include several dependencies:
composer require --dev debug
installssymfony/debug-pack
containssymfony/debug-bundle
symfony/monolog-bundle
symfony/var-dumper
in namespace controller create a class containing functions:
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class Main
{
public function main()
{
return new Response(
'<html><body>hello world!</body></html>');
}
}
main:
path: /main
controller: App\Controller\Main::main
install annotations: composer require annotations
(thx flex)
on top of each function or class as an annotation:
@Route("/main", name="myRoute")
- to see list of all routes:
php bin/console debug:router
- to see more detail on one specific route:
php bin/console debug:router route_name
- to see what route matches
- php bin/console router:match /route/address
route table has 4 properties:
Name | Method | Scheme | Host | Path |
---|---|---|---|---|
myRoute | ANY | ANY | ANY | main |
to use twig our controller should extends AbstractController
@Route attributes
name="myRoute"
set a name- set methods from HTML verbs
methods={"GET"}
- POST - GET - PUT - PATCH - DELETE
- route can contain condition based on context from request
- to see all services:
php bin/console debug:container
- to see more detail on one specific service:
php bin/console debug:container ServiceName
Autoconfigure sets the tags for us.
no direct component for DB but we can use Doctrine
Doctrine =
- ORM (Object Relational Mapping)
- mapping objects to classes and vice versa
- ODM (Object Document Mapper)
- used for MongoDB (NoSQL)
- DBAL (DB Abstraction Layer)
- Abstraction over PHP PDO
to install composer require doctrine maker
to warm-up cache (not important):
php bin/console cache:warmup --env=our_env --no-debug
to create DB for first time:
php bin/console doctrine:databse:create
to create Entity:
php bin/console make:entity EntityName
- Annotations on top of class:
- Entity
- Table
after create or editing Entities generate migrations.
to generate migrations:
php bin/console doctrine:migrations:diff
to use it:
php bin/console doctrine:migrations:migrate
to undo migrations:
php bin/console doctrine:migrations:migrate prev
REPO: holds all sql and makes db access only through one point and puts a layer over db.