How to know which version of Symfony I have?

前端 未结 11 1633
执念已碎
执念已碎 2020-12-07 19:35

I know that I have downloaded a Symfony2 project and started with but I have updated my vendor several times and I want to know which version of symfony I have

相关标签:
11条回答
  • 2020-12-07 20:01

    Use the following command in your Terminal/Command Prompt:

    php bin/console --version
    

    This will give you your Symfony Version.

    0 讨论(0)
  • 2020-12-07 20:03

    Although there are already many good answers I'd like to add an option that hasn't been mentioned. Using the command:

    php bin/console about
    

    you can get many details about the current project. The first section is about Symfony itself and looks like this:

    -------------------- ------------------------------------------- 
     Symfony                                                         
    -------------------- ------------------------------------------- 
     Version              4.2.3                                      
     End of maintenance   07/2019                                    
     End of life          01/2020                                    
    -------------------- ------------------------------------------- 
    

    I find the other information besides the version number very useful.

    There are also other sections providing details about the (framework) Kernel, PHP, Environment.

    0 讨论(0)
  • 2020-12-07 20:03

    we can find the symfony version using Kernel.php file but problem is the Location of Kernal Will changes from version to version (Better Do File Search in you Project Directory)

    in symfony 3.0 : my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php

    Check from Controller/ PHP File

    $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
    echo $symfony_version; // this will return version; **o/p:3.0.4-DEV**
    
    0 讨论(0)
  • 2020-12-07 20:04

    For Symfony 3.4

    Check the constant in this file vendor/symfony/http-kernel/Kernel.php

    const VERSION = '3.4.3';
    

    OR

    composer show | grep symfony/http-kernel
    
    0 讨论(0)
  • 2020-12-07 20:06

    From inside your Symfony project, you can get the value in PHP this way:

    $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
    
    0 讨论(0)
  • 2020-12-07 20:13

    If you want to dynamicallly display your Symfony 2 version in pages, for example in footer, you can do it this way.

    Create a service:

    <?php
    
    namespace Project\Bundle\DuBundle\Twig;
    
    class SymfonyVersionExtension extends \Twig_Extension
    {
    
    
     public function getFunctions()
     {
     return array(
     //this is the name of the function you will use in twig
     new \Twig_SimpleFunction('symfony_version', array($this, 'b'))
       );
     }
    
    public function getName()
    {
    //return 'number_employees';
     return 'symfony_version_extension';
    }   
    
    public function b()
    {
     $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
     return $symfony_version;
    }
    }
    

    Register in service.yml

     dut.twig.symfony_version_extension:
        class: Project\Bundle\DutBundle\Twig\SymfonyVersionExtension
        tags:
            - { name: twig.extension }
        #arguments: []
    

    And you can call it anywhere. In Controller, wrap it in JSON, or in pages example footer

     <p> Built With Symfony {{ symfony_version() }} Version MIT License</p>
    

    Now every time you run composer update to update your vendor, symfony version will also automatically update in your template.I know this is overkill but this is how I do it in my projects and it is working.

    0 讨论(0)
提交回复
热议问题