symfony/framework-standard-edition
Symfony Standard Edition: a full Symfony 3.4 application skeleton with AppBundle, Twig, Doctrine ORM/DBAL, Security, Swiftmailer, Monolog, and dev tools like Web Profiler and generators. Note: not compatible with Symfony 4+.
Installation:
composer create-project symfony/framework-standard-edition my_project
cd my_project
First Use Case:
Create a Controller:
php bin/console generate:controller HomePage
This generates a basic controller (src/AppBundle/Controller/HomePageController.php) with a index action and Twig template (templates/home_page/index.html.twig).
Run the Dev Server:
php bin/console server:run
Visit http://localhost:8000/home-page to see the generated page.
Key Files to Explore:
config/packages/ – Bundle configurations (e.g., doctrine.yaml, twig.yaml).src/AppBundle/ – Default bundle for custom logic (controllers, entities, services).templates/ – Twig templates for views.var/log/ – Monolog logs for debugging.Routing and Controllers:
@Route) or YAML/XML/PHP routing (config/routes.yaml).
// src/AppBundle/Controller/DefaultController.php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller
{
/**
* @Route("/hello/{name}", name="greet")
*/
public function index($name)
{
return new Response('<html><body>Hello '.$name.'</body></html>');
}
}
Database and Doctrine:
src/AppBundle/Entity/ (e.g., User.php).
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */
class User
{
/** @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer") */
private $id;
/** @ORM\Column(type="string", length=50) */
private $name;
}
php bin/console doctrine:generate:entities AppBundle
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Templating with Twig:
templates/base.html.twig) and reuse blocks.
{# templates/home_page/index.html.twig #}
{% extends 'base.html.twig' %}
{% block body %}
<h1>Welcome, {{ app.user.name }}!</h1>
{% endblock %}
{% include %} for modular templates (e.g., headers, footers).Services and Dependency Injection:
config/services.yaml or as class annotations.
# config/services.yaml
services:
AppBundle\Service\ExampleService:
arguments: ['@doctrine.orm.entity_manager']
public function __construct(ExampleService $exampleService) {
$this->exampleService = $exampleService;
}
Security:
config/packages/security.yaml:
security:
firewalls:
main:
anonymous: ~
form_login:
login_path: login
check_path: login_check
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
/**
* @Route("/admin", name="admin")
* @Security("is_granted('ROLE_ADMIN')")
*/
public function admin()
{
// ...
}
Logging and Debugging:
$this->get('logger')->info('User logged in', ['user_id' => $user->getId()]);
/_profiler/) in dev mode for request debugging.Email with Swiftmailer:
$message = (new \Swift_Message('Hello'))
->setFrom('sender@example.com')
->setTo('recipient@example.com')
->setBody($this->renderView('emails/hello.html.twig', ['name' => 'John']), 'text/html');
$this->get('mailer')->send($message);
Environment-Specific Configs:
config/packages/dev/monolog.yaml).%kernel.environment% in configs to switch behaviors.Asset Management:
assets component or bundles like symfony/webpack-encore-bundle for frontend assets.Testing:
tests/Functional/ and unit tests in tests/Unit/.php bin/console debug:router to validate routes in tests.Custom Bundles:
src/MyCustomBundle/).config/bundles.php:
return [
// ...
MyCustomBundle::class => ['all' => true],
];
Deprecation Warnings:
SensioFrameworkExtraBundle is deprecated in favor of Symfony’s built-in annotations.Doctrine Common Issues:
doctrine:migrations:diff after entity changes, then migrate.N+1 queries by using ->get() or ->find() with eager-loading:
$users = $entityManager->getRepository(User::class)->findAll();
foreach ($users as $user) {
$user->getPosts()->count(); // Avoids lazy-loading issues
}
Routing Conflicts:
name attributes for reverse routing:
$this->generateUrl('greet', ['name' => 'John']);
Twig Auto-Reloading:
php bin/console cache:clear
Security Misconfigurations:
security.yaml:
security:
csrf_protection:
enabled: true
masking in Monolog:
monolog:
handlers:
main:
processor: monolog.processor.mask_sensitive_information
Performance in Dev Mode:
APP_ENV=prod).--no-debug flag for faster CLI commands:
php bin/console doctrine:schema:update --no-debug
Web Profiler:
_profiler/ in dev mode for request/response details, SQL queries, and exceptions.use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
$dumper = new HtmlDumper();
$dumper->dump(new VarCloner(), $variable);
Logging Levels:
config/packages/monolog.yaml:
monolog:
handlers:
main:
level: debug # or info, warning, error
Command-Line Debugging:
--env=dev to enable debug mode for CLI commands:
php bin/console doctrine:query --env=dev
Common Errors:
cache:clear) or check autoloading (composer dump-autoload)..env (e.g., DATABASE_URL) and permissions.src/AppBundle/Command/:
namespace AppBundle\Command;
use Symfony\Component\Console
How can I help you explore Laravel packages today?