使用composer创建一个交响乐项目

时间:2018-03-13 23:28:22

标签: php symfony symfony4

我试图在我的Mac上使用symphony,所以我安装了symfony和composer以便开始开发,但是当我创建项目时,我遇到了一些问题:

composer create-project symfony/skeleton cost_management
Installing symfony/skeleton (v4.0.5)
  - Installing symfony/skeleton (v4.0.5): Loading from cache
Created project in cost_management
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 21 installs, 0 updates, 0 removals
  - Installing symfony/flex (v1.0.71): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.7.0): Loading from cache
  - Installing symfony/console (v4.0.6): Loading from cache
  - Installing symfony/routing (v4.0.6): Loading from cache
  - Installing symfony/http-foundation (v4.0.6): Loading from cache
  - Installing symfony/yaml (v4.0.6): Loading from cache
  - Installing symfony/framework-bundle (v4.0.6): Loading from cache
  - Installing symfony/http-kernel (v4.0.6): Loading from cache
  - Installing symfony/event-dispatcher (v4.0.6): Loading from cache
  - Installing psr/log (1.0.2): Loading from cache
  - Installing symfony/debug (v4.0.6): Loading from cache
  - Installing symfony/finder (v4.0.6): Loading from cache
  - Installing symfony/filesystem (v4.0.6): Loading from cache
  - Installing psr/container (1.0.0): Loading from cache
  - Installing symfony/dependency-injection (v4.0.6): Loading from cache
  - Installing symfony/config (v4.0.6): Loading from cache
  - Installing psr/simple-cache (1.0.1): Loading from cache
  - Installing psr/cache (1.0.1): Loading from cache
  - Installing symfony/cache (v4.0.6): Loading from cache
  - Installing symfony/dotenv (v4.0.6): Loading from cache
Writing lock file
Generating autoload files
Symfony operations: 4 recipes (7c280e93acfad83db0b06dac8600cc2d)
  - Configuring symfony/flex (>=1.0): From github.com/symfony/recipes:master
  - Configuring symfony/framework-bundle (>=3.3): From github.com/symfony/recipes:master
  - Configuring symfony/console (>=3.3): From github.com/symfony/recipes:master
  - Configuring symfony/routing (>=4.0): From github.com/symfony/recipes:master
Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!  
!!  Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "FileResource" from namespace "App".
!!  Did you forget a "use" statement for "Symfony\Component\Config\Resource\FileResource"? in /Users/gate11/Desktop/cost_management/src/Kernel.php:39
!!  Stack trace:
!!  #0 /Users/gate11/Desktop/cost_management/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(80): App\Kernel->configureContainer(Object(Symfony\Component\DependencyInjection\ContainerBuilder), Object(Symfony\Component\Config\Loader\DelegatingLoader))
!!  #1 [internal function]: App\Kernel->Symfony\Bundle\FrameworkBundle\Kernel\{closure}(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!!  #2 /Users/gate11/Desktop/cost_management/vendor/symfony/dependency-injection/Loader/ClosureLoader.php(38): call_user_func(Object(Closure), Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!!  #3 /Users/gate11/Desktop/cost_management/vendor/symfony/config/Loader/DelegatingLoader.php(40): Symfony\Component\DependencyInj in /Users/gate11/Desktop/cost_management/src/Kernel.php on line 39
!!  PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "FileResource" from namespace "App".
!!  Did you forget a "use" statement for "Symfony\Component\Config\Resource\FileResource"? in /Users/gate11/Desktop/cost_management/src/Kernel.php:39
!!  Stack trace:
!!  #0 /Users/gate11/Desktop/cost_management/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(80): App\Kernel->configureContainer(Object(Symfony\Component\DependencyInjection\ContainerBuilder), Object(Symfony\Component\Config\Loader\DelegatingLoader))
!!  #1 [internal function]: App\Kernel->Symfony\Bundle\FrameworkBundle\Kernel\{closure}(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!!  #2 /Users/gate11/Desktop/cost_management/vendor/symfony/dependency-injection/Loader/ClosureLoader.php(38): call_user_func(Object(Closure), Object(Symfony\Component\DependencyInjection\ContainerBuilder))
!!  #3 /Users/gate11/Desktop/cost_management/vendor/symfony/config/Loader/DelegatingLoader.php(40): Symfony\Component\DependencyInj in /Users/gate11/Desktop/cost_management/src/Kernel.php on line 39
!!  

我尝试了很多方法来安装它,我在他们的网站上看到了命令,所以我做了但是在安装它时仍然遇到了一些问题。 如果有人知道它有什么问题,或者我需要别的东西,我希望得到你的帮助。 感谢。

2 个答案:

答案 0 :(得分:0)

只需添加:

use Symfony\Component\Config\Resource\FileResource;

到src / Kernel.php的顶部,由于某种原因错过了。

之后,您可以继续composer install

答案 1 :(得分:0)

请将composer create-project symfony/skeleton cost_management替换为composer create-project symfony/website-skeleton cost_management

            **OR**

您可以使用PHP7.2在Ubuntu上安装和设置Symfony4应用程序,这些步骤通过temminal执行:

  1. composer create-project symfony/website-skeleton cost_management
  2. cd cost_management
  3. php -S 127.0.0.1:8000 -t public
  4. ctrl + c退出服务器运行composer install
  5. sudo chmod 777 -R var/cache/ var/log/
  6. 现在再次php -S 127.0.0.1:8000 -t public
  7. 现在,您可以通过此http://localhost:8000/检查您的浏览器,也可以直接访问http://localhost/project_directory/public/index.php
  8. Note:-  1.默认情况下,symfony 4设置为dev环境,但您可以设置     通过设置$_SERVER['APP_ENV']来设置您的环境  2.如果它正常工作,那么您将在底部看到404错误消息和分析器,因为它默认设置为dev模式。  3.按照文档Symfony 4 create your first page

    查看创建第一个控制器所需的内容