8000 Simplified some docs about getProjectDir · symfony/symfony-docs@4ecda82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ecda82

Browse files
committed
Simplified some docs about getProjectDir
1 parent d31f369 commit 4ecda82

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

deployment.rst

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -217,28 +217,15 @@ Troubleshooting
217217
Deployments not Using the ``composer.json`` File
218218
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219219

220-
Symfony applications provide a ``kernel.project_dir`` parameter and a related
221-
:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method.
222-
You can use this method to perform operations with file paths relative to your
223-
project's root directory. The logic to find that project root directory is based
224-
on the location of the main ``composer.json`` file.
225-
226-
If your deployment method doesn't use Composer, you may have removed the
227-
``composer.json`` file and the application won't work on the production server.
228-
The solution is to override the ``getProjectDir()`` method in the application
229-
kernel and return your project's root directory::
230-
231-
// src/Kernel.php
232-
// ...
233-
class Kernel extends BaseKernel
234-
{
235-
// ...
236-
237-
public function getProjectDir()
238-
{
239-
return dirname(__DIR__);
240-
}
241-
}
220+
The :ref:`project root directory <configuration-kernel-project-directory>`
221+
(whose value is used via the ``kernel.project_dir`` parameter and the
222+
:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method) is
223+
calculated automatically by Symfony as the directory where the main
224+
``composer.json`` file is stored.
225+
226+
In deployments not using the ``composer.json`` file, you'll need to override the
227+
:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method
228+
:ref:`as explained in this section <configuration-kernel-project-directory>`.
242229

243230
Learn More
244231
----------

reference/configuration/kernel.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,23 @@ The name of the kernel isn't usually directly important - it's used in the
6161
generation of cache files - and you probably will only change it when
6262
:doc:`using applications with multiple kernels </configuration/multiple_kernels>`.
6363

64+
.. _configuration-kernel-project-directory:
65+
6466
Project Directory
6567
~~~~~~~~~~~~~~~~~
6668

6769
**type**: ``string`` **default**: the directory of the project ``composer.json``
6870

69-
This returns the root directory of your Symfony project. It's calculated as
70-
the directory where the main ``composer.json`` file is stored.
71+
This returns the root directory of your Symfony project, which is used by
72+
applications to perform operations with file paths relative to the project's
73+
root directory.
7174

72-
If for some reason the ``composer.json`` file is not stored at the root of your
73-
project, you can override the :method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir`
74-
method to return the right project directory::
75+
By default, its value is calculated automatically as the directory where the
76+
main ``composer.json`` file is stored. If you don't use Composer, or have moved
77+
the ``composer.json`` file location or have deleted it entirely (for example in
78+
the production servers), you can override the
79+
:method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method to return
80+
the right project directory::
7581

7682
// src/Kernel.php
7783
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

0 commit comments

Comments
 (0)
0