gpt4 book ai didi

php - Symfony 第一页 - 自动加载器预期的类 […] 将在文件中定义

转载 作者:行者123 更新时间:2023-12-03 23:37:28 26 4
gpt4 key购买 nike

我检查过类似的问题,但由其他人发布,但我仍然看不到我的代码有什么问题。

我刚刚从文档中复制了它 - https://symfony.com/doc/3.4/page_creation.html

<?php

// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class LuckyController
{
/**
* @Route("/lucky/number")
*/
public function numberAction()
{
$number = mt_rand(0, 100);

return new Response(
'<html><body>Lucky number: '.$number.'</body></html>'
);
}
}

enter image description here

The autoloader expected class "App\Controller\LuckyController" to be defined in file "E:\projektai\php projektai\htdocs\mokomieji\weather_demo_3\vendor\composer/../../src\Controller\LuckyController.php". The file was found but the class was not in it, the class name or namespace probably has a typo in E:\projektai\php projektai\htdocs\mokomieji\weather_demo_3\config/services.yaml (which is loaded in resource "E:\projektai\php projektai\htdocs\mokomieji\weather_demo_3\config/services.yaml").

所以它说找到文件但找不到类。怎么找不到类?我看到了。它如何尝试搜索它?

composer.json

{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.0.8",
"symfony/console": "^3.4",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^3.4",
"symfony/lts": "^3",
"symfony/yaml": "^3.4"
},
"require-dev": {
"symfony/dotenv": "^3.4"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"id": "01C16444CCZTY1MPPEE5GJZ63G",
"allow-contrib": false
}
}
}

最佳答案

在我的情况下,我有一段时间没有使用 php,我也从教程中复制/粘贴,但我实际上忘记添加

<?php

在文件的开头。导致相同的错误消息。

关于php - Symfony 第一页 - 自动加载器预期的类 […] 将在文件中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47781152/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com