Symfony自动加载器预期类

问题描述 投票:1回答:1

我从symfony和php开始,我尝试调用这样的函数:

$login = Piwik::getCurrentUserLogin();

为此,我必须调用命名空间。

当我这样做Symfony时,它给我带来了这个错误:

自动加载器预期类“Etiam \ Nexus \ Communication \ ChatBundle \ Controller \ AuthenticationController”将在文件“/home/star/workspace/nexus/trunk/production/symfony/vendor/composer/../../src/中定义Etiam /的Nexus /通讯/ ChatBundle /控制器/ AuthenticationController.php”。找到该文件但该类不在其中,类名或命名空间可能有拼写错误。 (500内部服务器错误)

这是我的班级:

<?php

namespace Etiam\Nexus\Communication\ChatBundle\Controller;
namespace Piwik\Piwik;

use Etiam\Nexus\UserBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Piwik\Piwik;

class AuthenticationController extends Controller
{
  public function postCheckCredentialsAction(Request $request)
  {
    $arAuthRequest = json_decode($request->getContent(), true);

    $userUid = $arAuthRequest['user']['id'];
    $userPwd = $arAuthRequest['user']['password'];

    $directoryService = $this->get('etiam_nexus_directory.service.directory');

    $loginPattern = '/^@(.*):.*$/';
    preg_match_all($loginPattern, $userUid, $arUserIds);

    $user = $directoryService->getUser(
        $directoryService->getLocalEstablishment(),
        $arUserIds[1]
    );

    $login = Piwik::getCurrentUserLogin();
  }

//////////////// UPDATE //////////////////:

新错误:

尝试从命名空间“Piwik”加载类“Piwik”。您是否忘记了另一个命名空间的“use”语句? (500内部服务器错误)

我的课 :

<?php
/**
* Created by PhpStorm.
* User: floriane
* Date: 26/12/17
* Time: 15:49
*/

namespace Etiam\Nexus\Communication\ChatBundle\Controller;

use Etiam\Nexus\UserBundle\Entity\User;
use Piwik\Piwik; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class AuthenticationController extends Controller
{
   public function postCheckCredentialsAction(Request $request)
   {
    $arAuthRequest = json_decode($request->getContent(), true);

    $userUid = $arAuthRequest['user']['id'];
    $userPwd = $arAuthRequest['user']['password'];

    $directoryService = $this->get('etiam_nexus_directory.service.directory');

    $loginPattern = '/^@(.*):.*$/';
    preg_match_all($loginPattern, $userUid, $arUserIds);

    $user = $directoryService->getUser(
        $directoryService->getLocalEstablishment(),
        $arUserIds[1]
    );

      $login = Piwik::getCurrentUserLogin();

    if (!$user instanceof User) {
        return JsonResponse::create(
            array(
                'auth' => array(
                    'success' => false,
                    'mxid' => $userUid
                )
            )
        );
    }

    return JsonResponse::create(
        array(
            'auth' => array(
                'success' => true,
                'mxid' => $userUid,
                'profile' => array(
                    'display_name' => $user->getUserFullName(),
                    'three_pids' => array(
                        array(
                            'medium' => 'email',
                            'address' =>$user->getUseruniqname()
                        ),
                        array(
                            'medium' => 'msisdn',
                            'address' => $user->getPhonenumber()
                        )
                    )
                )
            )
        )
    );
}
}
php symfony
1个回答
2
投票

您应该为您的班级选择正确的命名空间。 删除namespace Piwik\Piwik;

该行基本上意味着您将您的类放在Piwik \ Piwik命名空间中,这不是您想要的。

© www.soinside.com 2019 - 2024. All rights reserved.