Udemy Flashcards
How to install Symfony?
composer create-project symfony/website-skeleton my-project
How to run Symfony?
php -S 127.0.0.1:8000 -t public
How to install template?
composer require twig
How to install Database?
composer require doctrine
How to easy for create controller?
composer require maker
How to create controller with command?
bin/console make:controller DefaultController
How to insert data to database?
bin/console make:migration
How to create table in database after insert data?
bin/console doctrine:migrations:migrate
Syntax Before Insert Data To Database
$entityManger = $this->getDoctrine()->getManager(); $user = new User; $user->setName('Seng Ponleu'); $user1 = new User; $user1->setName('Choem Rorn'); $user2 = new User; $user2->setName('Ren Rady'); $user3 = new User; $user3->setName('Horm Sopheap'); $entityManger->persist($user); $entityManger->persist($user1); $entityManger->persist($user2); $entityManger->persist($user3); exit($entityManger->flush());
How to set cookie?
$cookie = new Cookie( 'my_cookie', //Cookie name 'cookie value', // Cookie value time() + (2 * 365 * 24 * 60 * 60) // Expires after 2 years ); $res = new Response();
$res->headers->setCookie($cookie); $res->send();
How to remove cookie?
$res = new Response();
$res->headers->clearCookie('my_cookie'); $res->send();
How to set session?
$session->set(‘name’,’session value’);
if ($session->get('name')){ exit($session->get('name')); }
How to remove session?
$session->set(‘name’,’session value’);
$session->remove('name'); if ($session->has('name')){ exit($session->get('name')); }
GET/POST
exit($request->query->get(‘page’,’default’));
exit($request->server->get(‘HTTP_HOST’));
$request->isXmlHttpRequest(); //is it an Ajax request? $request->request->get('page'); $request->files->get('foo');
How to generate url?
{{ path(‘home’) }} <br></br>
{{ url(‘home’) }} <br></br>
{{ asset(‘images/logo.png’) }} <br></br>
{{ absolute_url(asset(‘images/logo.png’)) }}