且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Windows 上正确地将 Symfony 添加到 Path?

更新时间:2023-12-03 23:44:46

您需要添加一个批处理脚本来帮助窗口.

为了完整起见,以下是在 Windows 10 上测试所需的所有步骤:

For the sake of completeness, here are all steps required, tested on Windows 10:

  1. 获取symfony文件php -r "readfile('https://symfony.com/installer');"

symfony 文件移动到您选择的目录,因此在您的情况下 C:\wamp64\bin\php - 我个人制作了一个专用文件夹用于避免意外程序被拾取的命令:C:\commands

move the symfony file to a directory of your choice, so in your case C:\wamp64\bin\php - personally I made a dedicated folder for commands to avoid unintended programs being picked up on: C:\commands

确保目录,不是文件,已经添加到路径

此时如果你在命令提示符中输入symfony,它会询问你想用什么来执行程序,所以用处不大.

At this point if you enter symfony into the command prompt it will come up asking you what you want to execute the program with, so not much use.

为了解决这个问题,我们需要帮助它并告诉 windows 如何处理该文件——也就是说,让 PHP 运行它.

To remedy this we need to help it along and tell windows what to do with the file - that is, have PHP run it.

我们可以使用批处理脚本来实现:

We can achieve this using a batch script:

  1. 创建一个名为 symfony.bat 的文件,将它放在与您的 symfony 文件相同的目录中.

  1. create a file called symfony.bat, place it into the same directory as your symfony file.

在文件编辑器中打开批处理脚本并添加以下代码:

Open the batch script in a file editor and add the following code:

@ECHO OFF
php "%~dp0symfony" %*

一旦保存,symfony 命令应该可以正确运行,因为 Windows 现在将在输入命令时使用批处理文件.

Once saved the symfony command should run correctly as Windows will now use the batch file whenever the command is entered.